Skip to content

Instantly share code, notes, and snippets.

@mindon
Last active August 29, 2017 07:39
Show Gist options
  • Select an option

  • Save mindon/e455ad94ef396908b9ccb49d06bd878b to your computer and use it in GitHub Desktop.

Select an option

Save mindon/e455ad94ef396908b9ccb49d06bd878b to your computer and use it in GitHub Desktop.
javascript bisect
// javascript bisect
// const z=[0, 20, 50, 80, 110, 141, 173, 204, 235, 266, 297, 327]; console.log(bisect(25, z));
function bisect(v,d){let i=n=0,j=d.length;if(j==1){return 0}n=Math.floor(j/2);if(d[n]>v){j=n}else{i=n}return i+bisect(v,d.slice(i,j))}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment