Created
September 21, 2019 10:10
-
-
Save andreasonny83/17b23518aa1a0eb953e9a019bb32ab6f to your computer and use it in GitHub Desktop.
Flat an array recursively
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 _ = require('lodash'); | |
const x = [1, [2, 3, 4, [5, 6]], 7]; | |
const flat = (input) => Array.isArray(input) ? _.flatMap(input, item => flat(item)) : input; | |
const y = flat(x) | |
y // [1, 2, 3, 4, 5, 6, 7] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment