Created
February 1, 2014 15:09
-
-
Save sugendran/8753481 to your computer and use it in GitHub Desktop.
Example code for plzxplain
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
// 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