-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-Arrays.sol
59 lines (47 loc) · 1.53 KB
/
4-Arrays.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract ArraysExercise {
uint[] public numbers = [1,2,3,4,5,6,7,8,9,10];
address[] public senders;
uint[] public timestamps;
function getNumbers() public view returns(uint[] memory) {
return numbers;
}
function resetNumbers () public {
numbers = [1,2,3,4,5,6,7,8,9,10];
}
function appendToNumbers(uint[] calldata _toAppend) public {
for (uint i = 0; i < _toAppend.length; i++) {
numbers.push(_toAppend[i]);
}
}
function saveTimestamp(uint _unixTimestamp ) public {
timestamps.push(_unixTimestamp);
senders.push(msg.sender);
}
function afterY2K() public view returns (uint[] memory, address[] memory) {
uint count = 0;
for (uint i = 0; i < timestamps.length; i++) {
if (timestamps[i] > 946702800) {
count++;
}
}
uint[] memory filteredTimestamps = new uint[](count);
address[] memory filteredSenders = new address[](count);
uint index = 0;
for (uint i = 0; i < timestamps.length; i++) {
if (timestamps[i] > 946702800) {
filteredTimestamps[index] = timestamps[i];
filteredSenders[index] = senders[i];
index++;
}
}
return (filteredTimestamps, filteredSenders);
}
function resetSenders () public {
delete senders;
}
function resetTimestamps() public {
delete timestamps;
}
}