github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata/remove-from-array.sol (about) 1 pragma solidity 0.4.24; 2 contract Contract { 3 uint[] public values; 4 5 function Contract() { 6 } 7 8 function find(uint value) returns(uint) { 9 uint i = 0; 10 while (values[i] != value) { 11 i++; 12 } 13 return i; 14 } 15 16 function removeByValue(uint value) { 17 uint i = find(value); 18 removeByIndex(i); 19 } 20 21 function removeByIndex(uint i) { 22 while (i<values.length-1) { 23 values[i] = values[i+1]; 24 i++; 25 } 26 values.length--; 27 } 28 29 function getValues() constant returns(uint[]) { 30 return values; 31 } 32 33 function test() returns(uint[]) { 34 values.push(10); 35 values.push(20); 36 values.push(30); 37 values.push(40); 38 values.push(50); 39 removeByValue(30); 40 uint i=find(40); 41 removeByIndex(i); 42 return getValues(); 43 } 44 }