Linear Search
About
The simplest form of search, just linearly walking through a DS and checking if the value in the current position is the desired value.
Implementation on Arrays
function linearSearch(haystack: number[], needle: number): boolean {
for (let i = 0; i < haystack.length; i++) {
if (haystack[i] === needle) return true;
}
return false;
}Last updated