Created
September 2, 2020 06:37
-
-
Save jamesliu96/eeec6fdaefdcb97c6c104d285c1b2c03 to your computer and use it in GitHub Desktop.
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
export const flatten = (arr) => [].concat(...arr); | |
function* _flatten(arr) { | |
for (const item of arr) { | |
if (Array.isArray(item)) { | |
yield* _flatten(item); | |
} else { | |
yield item; | |
} | |
} | |
} | |
export const deepFlatten = (arr) => [..._flatten(arr)]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment