Skip to content

Instantly share code, notes, and snippets.

@Mayur1496
Created September 25, 2020 11:16
Show Gist options
  • Save Mayur1496/2e24c609527a31ba24be90118f8f6c4f to your computer and use it in GitHub Desktop.
Save Mayur1496/2e24c609527a31ba24be90118f8f6c4f to your computer and use it in GitHub Desktop.
Sample Solidity Contract
pragma solidity ^0.5.5;
library Search {
function indexOf(uint[] storage self, uint value) public view returns (uint) {
for (uint i = 0; i < self.length; i++) if (self[i] == value) return i;
return uint(-1);
}
}
contract Test {
uint[] data;
constructor() public {
data.push(1);
data.push(2);
data.push(3);
data.push(4);
data.push(5);
}
function isValuePresent() external view returns(uint){
uint value = 4;
//search if value is present in the array using Library function
uint index = Search.indexOf(data, value);
return index;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment