Arrays
An array is a collection of items stored at contiguous (unbreakable) memory locations.
const a = new ArrayBuffer(6);
const a8 = new Uint8Array(a);
// ArrayBuffer { [Uint8Contents]: <00 00 00 00 00 00>, [byteLength]: 6 }
In JavaScript, arrays aren't primitives but are instead Array objects with special characteristics.
const a = []; // This isn't an actual array.
Linear Search
Linear search is the most straightforward way to find a specific value in a collection of data. We find our needle by walking through the array and checking for the needle with a conditional statement. Worst case time complexity would be O(n).
function linear_search(heystack: number[], needle: number): boolean {
for (let i = 0; i < heystack.length; i++) {
if (heystack[i] === needle) {
return true;
}
}
return false;
}