Last active
January 10, 2018 08:01
-
-
Save industral/7d68d10f8b3c241245aae51d36396685 to your computer and use it in GitHub Desktop.
Array flattering
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 array = [[['a','b','c'],[1,2,3]],[],[['d','e','f','g','h'],[4,5,6,7]]] | |
function flat(data) { | |
return data.reduce((r, e) => r.concat(Array.isArray(e) ? flat(e) : e), []) | |
} | |
console.log(flat(array)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment