-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindexOf.js
More file actions
33 lines (25 loc) · 779 Bytes
/
indexOf.js
File metadata and controls
33 lines (25 loc) · 779 Bytes
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
function middleEarth(arr) {
const frodo = arr.indexOf('Frodo')
// console.log(frodo)
const sam = arr.indexOf('Sam')
// console.log(sam)
if (frodo - sam === -1 || sam - frodo === -1) {
console.log('true')
return true
} else {
console.log('false')
return false
}
}
middleEarth(['Frodo', 'Sam', 'Gandalf']) //➞ true
middleEarth(['Frodo', 'Saruman', 'Sam']) //➞ false
middleEarth(['Orc', 'Sam', 'Frodo', 'Legolas']) //➞ true
// SIMPLE indexOf EXAMPLE:
// const beasts = ['ant', 'bison', 'camel', 'duck', 'bison']
// console.log(beasts.indexOf('bison'))
// // expected output: 1
// // start from index 2
// console.log(beasts.indexOf('bison', 2))
// // expected output: 4
// console.log(beasts.indexOf('giraffe'))
// // expected output: -1