1// arr.indexOf(val)
2function linearSearchIndexOf(arr, val) {
3 for (let i = 0; i < arr.length; i++) {
4 if (arr[i] === val) {
5 return i;
6 }
7 }
8 return -1;
9}
10
11// arr.includes(val)
12function linearSearchIncludes(arr, val) {
13 for (let i = 0; i < arr.length; i++) {
14 if (arr[i] === val) {
15 return true;
16 }
17 }
18 return false;
19}
20
21// arr.find(cb)
22// cb = CallBack Function
23
24function linearSearchFind(arr, cb) {
25 for (let i = 0; i < arr.length; i++) {
26 if (cb(arr[i]) === true) {
27 return arr[i];
28 }
29 }
30 return undefined;
31}
1function searchAlgorithm (number){
2
3 for(let i = 0; i< number; i++){
4 if(number == array[i]){
5 console.log("Found it, it's at index " + i)
6 }else{
7 console.log("Not found")
8 }
9
10 };
11
12}
13
14
15var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
16
17searchAlgorithm(5)
1function linearSearch(value, list) {
2 let found = false;
3 let position = -1;
4 let index = 0;
5
6 while(!found && index < list.length) {
7 if(list[index] == value) {
8 found = true;
9 position = index;
10 } else {
11 index += 1;
12 }
13 }
14 return position;
15}
16