Created
July 10, 2022 11:40
-
-
Save Akifcan/f1e1ea793778aec9ac62247c15759f32 to your computer and use it in GitHub Desktop.
Flatten
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 x = [[5, 3, 2], 5, 1, 99, [3, [4, 5]]] | |
const flatten = [] | |
function myFlat(arr){ | |
arr.forEach(i => { | |
if(Array.isArray(i)){ | |
myFlat(i) | |
}else{ | |
flatten.push(i) | |
} | |
}) | |
return flatten | |
} | |
console.log(myFlat(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment