Skip to content

Instantly share code, notes, and snippets.

@sugendran
Created February 1, 2014 15:09
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 sugendran/8753481 to your computer and use it in GitHub Desktop.
Save sugendran/8753481 to your computer and use it in GitHub Desktop.
Example code for plzxplain
// binary search function taken from http://rosettacode.org/wiki/Binary_search
function binary_search_recursive(a, value, lo, hi) {
if (hi < lo)
return null;
var mid = Math.floor((lo+hi)/2);
if (a[mid] > value)
return binary_search_recursive(a, value, lo, mid-1);
else if (a[mid] < value)
return binary_search_recursive(a, value, mid+1, hi);
else
return mid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment