Skip to content

Instantly share code, notes, and snippets.

@danprince
Created October 8, 2013 18:19
Show Gist options
  • Save danprince/6889099 to your computer and use it in GitHub Desktop.
Save danprince/6889099 to your computer and use it in GitHub Desktop.
Takes an array of integers, strings and arrays. Finds all integers at any depth and returns the sum.
sum = (i) ->
i.map((e) ->
(if typeof e is "object" then sum(e) else e)
).filter((e) ->
typeof e is "number"
).reduce (p, c) ->
p + c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment