Created
August 14, 2018 08:10
-
-
Save vamshi9666/13306ac0c7552e95eee5d4762d77a5fa 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
const input_array = [[1,2,[3]],4] | |
function flatten(arr) { | |
return arr.reduce(function (flat, toFlatten) { | |
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); | |
}, []); | |
} | |
flatten(input_array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment