Last active
May 13, 2016 09:01
-
-
Save yxy/f989e56ea808d24a87a5451d8199cda5 to your computer and use it in GitHub Desktop.
flatten array snippet
This file contains 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
flatten = function (a, b) { | |
if (!Array.isArray(a)) { | |
a = [a]; | |
} | |
return a.concat(b); | |
} | |
// usage | |
var aa = [[1], [2, 3], [4, 5]]; | |
aa.reduce(flatten); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment