Last active
December 18, 2015 17:28
-
-
Save hikari-no-yume/5818399 to your computer and use it in GitHub Desktop.
This file contains 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
function bsearch(list, value) { | |
var index1, index2; | |
if (list.length === 1) { | |
return list[0]; | |
} else if (list.length === 0) { | |
return null; | |
} | |
index1 = 0; | |
index2 = Math.floor(list.length / 2); | |
if (list[index2] === value) { | |
return list[index2] | |
} else if (list[index2] < value) { | |
return bsearch(list.slice(index2), value); | |
} else { | |
return bsearch(list.slice(index1, index2), value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment