Skip to content

Instantly share code, notes, and snippets.

@tristanstraub
Created August 29, 2014 06:25
Show Gist options
  • Save tristanstraub/c453d572b97513090d2c to your computer and use it in GitHub Desktop.
Save tristanstraub/c453d572b97513090d2c to your computer and use it in GitHub Desktop.
node_puzzle_3
'use strict'
exports.add = (arr) ->
if arr.length is 0
return [1]
result = []
i = arr.length - 1
c = 1
while i >= 0
x = arr[i] + c
result.unshift x % 10
c = Math.floor(x/10)
i--
if c
result.unshift c
# shrink
while result[0] is 0
result.shift()
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment