Created
January 19, 2019 00:52
-
-
Save amarsyla/cb40bafa7997e7b4f047bafce1b80f2b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 flatten = (array) => { | |
let flattened = []; | |
for (const item of array) { | |
flattened = flattened.concat(Array.isArray(item) ? flatten(item) : item); | |
} | |
return flattened; | |
}; | |
console.log(flatten([[1,2,[3]],4])); // [1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment