Created
April 2, 2017 11:36
-
-
Save a-eid/6130878a5b638bd6fc9588b76651e8d8 to your computer and use it in GitHub Desktop.
simple binary search example ...
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
const bsearch = (arr , start , end , el) => { | |
if(start > end) return -1 | |
let mid = Math.round((start + end) / 2) | |
if(mid == el) return mid | |
else if ( mid < el ) return bsearch(arr , mid + 1 , end , el) | |
else if ( mid > el ) return bsearch(arr , start , mid - 1 , el) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment