Skip to content

Instantly share code, notes, and snippets.

@AliveDD
Last active October 15, 2019 16:23
Show Gist options
  • Save AliveDD/2f3daa48ff577b8d6eb278c73fc65b76 to your computer and use it in GitHub Desktop.
Save AliveDD/2f3daa48ff577b8d6eb278c73fc65b76 to your computer and use it in GitHub Desktop.
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