Skip to content

Instantly share code, notes, and snippets.

@arton arton/
Last active Aug 4, 2018

What would you like to do?
binary search for Coffee
binsearch = (a, low, high, target) ->
if low == high || low + 1 == high
if a[low] < target then return low + 1 else return low
mid = Math.floor((low + high) / 2)
if a[mid] == target
return mid
else if target > a[mid]
binsearch(a, mid + 1, high, target)
binsearch(a, low, mid - 1, target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.