Created
July 12, 2016 17:29
-
-
Save tushar-borole/938549ccbe087c80b982038d6d4e23ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array = [ | |
1, | |
5, | |
10, | |
15, | |
20, | |
25, | |
30, | |
35, | |
40, | |
45, | |
50, | |
55, | |
60, | |
65, | |
70, | |
75, | |
80, | |
85, | |
90, | |
95, | |
100 | |
] | |
while (array.length != 0) { | |
search = 15 | |
console.log(array) | |
var i = Math.round(array.length / 2) | |
console.log(i) | |
if (search > array[i]) { | |
array = array.slice(i, array.length) | |
} else if (search < array[i]) { | |
array = array.slice(0, i) | |
} else if (array[i] == search) { | |
alert('value found') | |
break | |
}else{ | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment