15 lines
437 B
CoffeeScript
15 lines
437 B
CoffeeScript
exports.adder = (input) ->
|
|
if input is '' then return '0'
|
|
else if input isnt '' and input.length is 1
|
|
return parseInt(input[0])
|
|
else if input.length > 1
|
|
if /^\/\//.test(input) is true
|
|
endIndex = input.search(/\n/)
|
|
customDelimiter = input.slice 2, endIndex
|
|
input = input.slice endIndex
|
|
input = input.split /\D/
|
|
result = 0
|
|
for num in input
|
|
if num isnt '' then result = result + parseInt(num)
|
|
return result
|
|
|