Skip to content

Instantly share code, notes, and snippets.

@Jagathishrex
Created November 11, 2019 10:18
Show Gist options
  • Save Jagathishrex/e1365ef3be998b657a3c3235c93e4f64 to your computer and use it in GitHub Desktop.
Save Jagathishrex/e1365ef3be998b657a3c3235c93e4f64 to your computer and use it in GitHub Desktop.
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