Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
8
Task/Binary-search/CoffeeScript/binary-search-1.coffee
Normal file
8
Task/Binary-search/CoffeeScript/binary-search-1.coffee
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
binarySearch = (xs, x) ->
|
||||
do recurse = (low = 0, high = xs.length - 1) ->
|
||||
mid = Math.floor (low + high) / 2
|
||||
switch
|
||||
when high < low then NaN
|
||||
when xs[mid] > x then recurse low, mid - 1
|
||||
when xs[mid] < x then recurse mid + 1, high
|
||||
else mid
|
||||
Loading…
Add table
Add a link
Reference in a new issue