Created
October 9, 2024 22:24
-
-
Save henvo/38b517ab84f61b1cfe7f926b53e570c3 to your computer and use it in GitHub Desktop.
Simple flatten function in JavaScript
This file contains 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 flatten = (input, ary = []) => { | |
if (!Array.isArray(input)) { return ary.push(input) }; | |
input.forEach((v) => flatten(v, ary)); | |
return ary; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment