Created
February 28, 2019 20:39
-
-
Save pedro-victor/4f3556551a42f2e4858996029ad79b58 to your computer and use it in GitHub Desktop.
Flatten multi-dimensional arrays 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 rec = (arr) => arr.reduce((a, b) => a.concat(Array.isArray(b) ? rec(b) : b), []) | |
rec([[1, 2, [3]], 4]) | |
// [1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment