Last active
April 9, 2018 09:16
-
-
Save fernandocamargo/2fcd6764bb26b65267515bbb4ed96df0 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
const test = [[1, [2, [3]]], 4]; | |
const dig = (stack, object) => | |
Array.isArray(object) ? flatten(object, stack) : stack.concat(object); | |
const flatten = (input, output = []) => input.reduce(dig, output); | |
console.clear(); | |
console.log(flatten(test)); // [1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment