-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraysExercise.sol
More file actions
68 lines (56 loc) · 1.72 KB
/
ArraysExercise.sol
File metadata and controls
68 lines (56 loc) · 1.72 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
67
68
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract ArraysExercise {
uint[] public numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
uint[] private initialNumbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
uint[] public timestamps;
address[] public senders;
function getNumbers() external view returns (uint[] memory) {
return numbers;
}
function resetNumbers() public returns (uint[] memory) {
numbers = initialNumbers;
return numbers;
}
function appendToNumbers(uint[] calldata _toAppend) public {
for (uint i = 0; i < _toAppend.length; i++) {
numbers.push(_toAppend[i]);
}
}
function saveTimestamp(uint _unixTimestamp) public {
senders.push(msg.sender);
timestamps.push(_unixTimestamp);
}
function afterY2K()
external
view
returns (uint[] memory, address[] memory)
{
uint[] memory recentTimes;
address[] memory recentSenders;
uint count = 0;
for (uint i = 0; i < timestamps.length; i++) {
if (timestamps[i] > 946702800) {
count++;
}
}
recentTimes = new uint[](count);
recentSenders = new address[](count);
count = 0;
for (uint i = 0; i < timestamps.length; i++) {
if (timestamps[i] > 946702800) {
recentTimes[count] = timestamps[i];
recentSenders[count] = senders[i];
count++;
}
}
return (recentTimes, recentSenders);
}
//reset storage variables
function resetSenders() public {
delete senders;
}
function resetTimestamps() public {
delete timestamps;
}
}