Skip to content

Instantly share code, notes, and snippets.

@forrest-akin
Last active October 9, 2020 16:34
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 forrest-akin/dae4a8106b4d410bd2f97dc162723935 to your computer and use it in GitHub Desktop.
Save forrest-akin/dae4a8106b4d410bd2f97dc162723935 to your computer and use it in GitHub Desktop.
function search ( nums , target ) {
for ( let low = 0 , high = nums.length - 1 , ndx
; low <= high
; nums[ ndx ] < target ? low = ndx + 1 : high = ndx - 1
) if ( ndx = Math.floor( ( high - low ) / 2 ) + low
, nums[ ndx ] === target
) return ndx
return -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment