RosettaCodeData/Task/Flatten-a-list/CoffeeScript/flatten-a-list-1.coffee

11 lines
219 B
CoffeeScript
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
flatten = (arr) ->
arr.reduce ((xs, el) ->
if Array.isArray el
xs.concat flatten el
else
xs.concat [el]), []
# test
list = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
console.log flatten list