github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata-istanbul/remove-from-array.sol (about)

     1  pragma solidity ^0.8.4;
     2  contract Contract {
     3      uint[] public values;
     4  
     5      function find(uint value) internal view returns(uint) {
     6          uint i = 0;
     7          while (values[i] != value) {
     8              i++;
     9          }
    10          return i;
    11      }
    12  
    13      function removeByValue(uint value) public {
    14          uint i = find(value);
    15          removeByIndex(i);
    16      }
    17  
    18      function removeByIndex(uint i) public {
    19          while (i<values.length-1) {
    20              values[i] = values[i+1];
    21              i++;
    22          }
    23          values.pop();
    24      }
    25  
    26      function getValues() internal view returns(uint[] storage) {
    27          return values;
    28      }
    29  
    30      function test() public returns(uint[] memory) {
    31          values.push(10);
    32          values.push(20);
    33          values.push(30);
    34          values.push(40);
    35          values.push(50);
    36          removeByValue(30);
    37          uint i=find(40);
    38          removeByIndex(i);
    39          return getValues();
    40      }
    41  }