Created
February 2, 2017 16:42
-
-
Save razchiriac/71ddcb75f2e4b57c38b30ca42b04d973 to your computer and use it in GitHub Desktop.
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
var startArr = [[1,2,[3]],[[4]]]; | |
function flatten(arr) { | |
return arr.reduce(function (flat, toFlatten) { | |
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); | |
}, []); | |
} | |
console.log(flatten(startArr)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment