Created
November 11, 2019 10:18
-
-
Save Jagathishrex/e1365ef3be998b657a3c3235c93e4f64 to your computer and use it in GitHub Desktop.
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
class Search { | |
constructor(input) { | |
this.input = input | |
} | |
linearSearch(target) { | |
const array = this.input | |
const len = array.length | |
for (let i = 0; i < len; i++) { | |
if (array[i] === target) { | |
return 'Element present in index ' + i | |
} | |
} | |
return 'Element not found' | |
} | |
} | |
var search = new Search([1, 2, 3, 4, 5, 6]) | |
search.linearSearch(3) // Element present in index 2 | |
search.linearSearch(30) // Element not found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment