Created
October 7, 2016 00:23
-
-
Save ghostffcode/551b148295a99b19b60f6c0b927181f1 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 arr = [1,2, 3, [4,5,6, [45,26,25,89]], 7,8,9] | |
function flatten(myArray) { | |
return myArray.reduce(function (x, y) { | |
return x.concat(Array.isArray(y) ? flatten(y) : y); | |
}, []); | |
} | |
console.log(flatten(arr)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment