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 unflattened = [[1,2,[3]],4] | |
const flattened = [1, 2, 3, 4] | |
// It would be much easier with the already provided in the language: const result = unflattened.flat(Infinity) | |
const flatten = arr => arr.reduce((flat, next) => flat.concat(Array.isArray(next) ? flatten(next) : next), []) | |
const result = flatten(unflattened) | |
expect(result).toEqual(flattened) |