Created
September 25, 2020 11:16
-
-
Save Mayur1496/2e24c609527a31ba24be90118f8f6c4f to your computer and use it in GitHub Desktop.
Sample Solidity Contract
This file contains 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
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