Last active
October 15, 2019 16:23
-
-
Save AliveDD/2f3daa48ff577b8d6eb278c73fc65b76 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 complexArray = [[1, 2], 3, [5, [6, 7]]] | |
const flatten = (complexArray) => { | |
const output = []; | |
(function flatDepth(complexArray) { | |
array.forEach((data) => { | |
if (Array.isArray(data)) { | |
flatDepth(data); | |
} else { | |
output.push(data); | |
} | |
}); | |
})(array); | |
return output; | |
} | |
console.log(flatten(complexArray)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment