-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraysExercise.sol
More file actions
66 lines (53 loc) · 1.65 KB
/
ArraysExercise.sol
File metadata and controls
66 lines (53 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;
contract Submission {
uint[] private numbers;
uint[] private timestamps;
address[] private senders;
constructor() {
resetNumbers();
}
function resetNumbers() public {
delete numbers;
for (uint i = 1; i <= 10; i++) {
numbers.push(i);
}
}
function appendToNumbers(uint[] calldata _toAppend) external {
for (uint i = 0; i < _toAppend.length; i++) {
numbers.push(_toAppend[i]);
}
}
function getNumbers() external view returns (uint[] memory) {
return numbers;
}
function saveTimestamp(uint _unixTimestamp) external {
timestamps.push(_unixTimestamp);
senders.push(msg.sender);
}
function resetTimestamps() external {
delete timestamps;
}
function resetSenders() external {
delete senders;
}
function afterY2K() external view returns (uint[] memory, address[] memory) {
uint count = 0;
for (uint i = 0; i < timestamps.length; i++) {
if (timestamps[i] >= 946702900) {
count++;
}
}
uint[] memory filteredTimestamps = new uint[](count);
address[] memory filteredAddresses = new address[](count);
uint counter = 0;
for (uint i = 0; i < timestamps.length; i++) {
if (timestamps[i] >= 946702900) {
filteredTimestamps[counter] = timestamps[i];
filteredAddresses[counter] = senders[i];
counter++;
}
}
return (filteredTimestamps, filteredAddresses);
}
}