forked from raineorshine/solidity-by-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove-from-array.sol
More file actions
41 lines (35 loc) · 815 Bytes
/
Copy pathremove-from-array.sol
File metadata and controls
41 lines (35 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
contract Contract {
uint[] public values;
function Contract() {
}
function find(uint value) returns(uint) {
uint i = 0;
while (values[i] != value) {
i++;
}
return i;
}
function removeByValue(uint value) {
uint i = find(value);
removeByIndex(i);
}
function removeByIndex(uint i) {
while (i<values.length-1) {
values[i] = values[i+1];
i++;
}
values.length--;
}
function getValues() constant returns(uint[]) {
return values;
}
function test() returns(uint[]) {
values.push(10);
values.push(20);
values.push(30);
values.push(40);
values.push(50);
removeByValue(30);
return getValues();
}
}