-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-Linear-Search-O(N)-Slower.js
More file actions
48 lines (35 loc) · 1.04 KB
/
01-Linear-Search-O(N)-Slower.js
File metadata and controls
48 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Linear Search
// Time: O(n) "Big O of N time"
// .indexOf //n //-1
// .includes //true //false
// .find
// .findIndex
const linearSearch = (arr,val) => {
///////////////////////////////////
/////// **** for loop ***** //////
///////////////////////////////////
// for(let i = 0; i < arr.length; i++){
// let eachVal = arr[i]
// if(eachVal === val)return i
// }
// return -1
///////////////////////////////////
/////// **** .indexOf ***** //////
///////////////////////////////////
// let i = arr.indexOf(val)
// return i
///////////////////////////////////
/////// **** .includes ***** //////
///////////////////////////////////
// let i = arr.includes(val)
// return i //true
}
//console.log(linearSearch([10,15,20, 25, 30],15))
////////////////////////////////////////////
/////// **** .find .findIndex ***** ////////
////////////////////////////////////////////
let arr = [-1,-2,3]
let found = arr.find(function (val){
return val > 0
})
console.log(found)