3 ms·
Here's my cheating version that uses a third-party library: add1_cheating = (arr, val, n) -> n = arr.length if n is 0 start = if n < 0 then arr
by azylman 14y ago
Here's my cheating version that uses a third-party library:
add1_cheating = (arr, val, n) ->
n = arr.length if n is 0
start = if n < 0 then arr.length else 0
end = if n < 0 then 0 else arr.length
step = n/(Math.abs n)
n = Math.abs n
count = 0
for i in _.range start, end, step
break if count > n
arr[i]++ if arr[i] is val
count++
return arr