Created
August 29, 2014 06:25
-
-
Save tristanstraub/c453d572b97513090d2c to your computer and use it in GitHub Desktop.
node_puzzle_3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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