News for hackers. Stuff that matters.
Re:Array Iteration Interview Problem by azylman on Wednesday August 01, 2012 @09:24PM (#4326721)
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

There are no comments on this comment yet.