Skip to content

Instantly share code, notes, and snippets.

@fsrc
Created April 24, 2014 11:42
Show Gist options
  • Save fsrc/11251498 to your computer and use it in GitHub Desktop.
Save fsrc/11251498 to your computer and use it in GitHub Desktop.
Reduce-example
reduce = (input, iterator, memo) ->
if input.length == 0
memo
else
reduce(input.slice(1), iterator, iterator(memo, input[0]))
sum = (input) ->
reduce(input, (memo, item) ->
memo += item
memo
, 0)
result = sum([1,2,3])
console.dir result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment