Created
March 28, 2020 13:10
-
-
Save emmabostian/0fbe2ea041b4eb9389e93de7d18e308c 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
function flattenArr(arr) { | |
let flattenedArr = []; | |
function flatten(subArr) { | |
for (let i of subArr) { | |
if (Array.isArray(i)) { | |
flatten(i); | |
continue; | |
} | |
flattenedArr.push(i); | |
} | |
} | |
flatten(arr); | |
return flattenedArr; | |
} | |
console.log(flattenArr([1, 2, [3, 4], [5, 6, [7]]])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment