mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
Create jusia
This commit is contained in:
parent
2037c53e7a
commit
1267898398
1 changed files with 72 additions and 0 deletions
72
jusia
Normal file
72
jusia
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8.17;
|
||||||
|
|
||||||
|
contract ArraysExercise {
|
||||||
|
uint[] numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||||
|
uint[] timestamps;
|
||||||
|
address[] senders;
|
||||||
|
|
||||||
|
uint256 constant Y2K = 946702800;
|
||||||
|
|
||||||
|
function getNumbers() external view returns (uint[] memory) {
|
||||||
|
uint[] memory results = new uint[](numbers.length);
|
||||||
|
|
||||||
|
for(uint i=0; i<numbers.length; i++) {
|
||||||
|
results[i] = numbers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetNumbers() public {
|
||||||
|
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendToNumbers(uint[] calldata _toAppend) public {
|
||||||
|
uint _counter = _toAppend.length;
|
||||||
|
for (uint i; i < _counter; i++) {
|
||||||
|
numbers.push(_toAppend[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveTimestamp(uint _unixTimestamp) public {
|
||||||
|
timestamps.push(_unixTimestamp);
|
||||||
|
senders.push(msg.sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
function afterY2K() public view returns (uint256[] memory, address[] memory) {
|
||||||
|
|
||||||
|
uint256 counter = 0;
|
||||||
|
|
||||||
|
for (uint i = 0; i < timestamps.length; i++) {
|
||||||
|
if (timestamps[i] > Y2K) {
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint256[] memory timestampsAfterY2K = new uint256[](counter);
|
||||||
|
address[] memory sendersAfterY2K = new address[](counter);
|
||||||
|
|
||||||
|
uint256 index = 0;
|
||||||
|
|
||||||
|
for (uint i = 0; i < timestamps.length; i++) {
|
||||||
|
if (timestamps[i] > Y2K) {
|
||||||
|
timestampsAfterY2K[index] = timestamps[i];
|
||||||
|
sendersAfterY2K[index] = senders[i];
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (timestampsAfterY2K, sendersAfterY2K);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetSenders() public {
|
||||||
|
delete senders;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetTimestamps() public {
|
||||||
|
delete timestamps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in a new issue