linear search | JavaScript

December 24th, 2021 07:59:43 PM

					
const linearSearch = (arr, item) => { for (const i in arr) { if (arr[i] === item) return +i; } return -1; }; linearSearch([2, 9, 9], 9); // 1 linearSearch([2, 9, 9], 7); // -1

Featured Posts