Skip to content

Instantly share code, notes, and snippets.

@Akifcan
Created July 10, 2022 11:40
Show Gist options
  • Save Akifcan/f1e1ea793778aec9ac62247c15759f32 to your computer and use it in GitHub Desktop.
Save Akifcan/f1e1ea793778aec9ac62247c15759f32 to your computer and use it in GitHub Desktop.
Flatten
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