Created
June 29, 2016 18:23
-
-
Save raineorshine/e080d25453a4c075cfcf89f72f8357cd to your computer and use it in GitHub Desktop.
A Solidity library to remove elements from an array.
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
library ArrayUtil { | |
/** Finds the index of a given value in an array. */ | |
function IndexOf(uint[] values, uint value) returns(uint) { | |
uint i = 0; | |
while (values[i] != value) { | |
i++; | |
} | |
return i; | |
} | |
/** Removes the given value in an array. */ | |
function RemoveByValue(uint[] values, uint value) { | |
uint i = IndexOf(value); | |
RemoveByIndex(i); | |
} | |
/** Removes the value at the given index in an array. */ | |
function RemoveByIndex(uint[] values, uint i) { | |
while (i<values.length-1) { | |
values[i] = values[i+1]; | |
i++; | |
} | |
values.length--; | |
} | |
} |
And you don't pass values(array on which to execute operation) anywhere.
You're not receiving the uint[] as a storage, I believe it will create a copy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should make a new variable length. It won't compile at least in the latest versions of solidity.