Created
September 18, 2020 19:28
-
-
Save arnonate/e3cfb28291d89ac6a7ce6fc07663614a 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
// Flatten an Array of Arrays without using .flat() | |
function flatten(array) { | |
return array.reduce((acc, item) => { | |
if (Array.isArray(item)) { | |
acc = acc.concat(flatten(item)); | |
} else { | |
acc.push(item); | |
} | |
return acc; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment