Skip to content

Instantly share code, notes, and snippets.

@allenhwkim
Created December 21, 2013 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allenhwkim/8071013 to your computer and use it in GitHub Desktop.
Save allenhwkim/8071013 to your computer and use it in GitHub Desktop.
The fastest search ever for large amount of data http://jsperf.com/binary-search-1234
function search(arr, o) {
var l = 0,
u = arr.length,
m;
while (l <= u) {
if (o > arr[(m = ((l + u) >> 1))])
l = m + 1;
else
u = (o == arr[m]) ? -2 : m - 1;
}
return (u == -2) ? m : -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment