Created
August 22, 2016 15:01
-
-
Save asvny/5c16a3c33604d3fa74ac5ee2f80c497d to your computer and use it in GitHub Desktop.
functional flatten
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
const flatten = xs => { | |
let next = (acc, xs) => xs.reduce((x, y) => Array.isArray(y) | |
? next(x, y) | |
: (x[x.length] = y, x) | |
, acc); | |
return next([], xs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment