Skip to content

Instantly share code, notes, and snippets.

@hikari-no-yume
Last active December 18, 2015 17:28
Show Gist options
  • Save hikari-no-yume/5818399 to your computer and use it in GitHub Desktop.
Save hikari-no-yume/5818399 to your computer and use it in GitHub Desktop.
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