-
-
Save josemvcerqueira/b9d5fdc693a2060b14f242f96d5c900c to your computer and use it in GitHub Desktop.
Array in Array example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity >=0.8.9; | |
| contract Test { | |
| uint256[][20] public array; | |
| mapping(uint256 => bool) private _exists; | |
| function push(uint256 index, uint256 indexChildren, uint256 value) external { | |
| bool exists = _exists[index]; | |
| if (!exists) { | |
| uint256[] memory newArray = new uint256[](20); | |
| array[index] = newArray; | |
| _exists[index] = true; | |
| } | |
| uint256[] memory storedArray = array[index]; | |
| storedArray[indexChildren] = value; | |
| array[index] = storedArray; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment