Created
October 17, 2018 07:32
-
-
Save panvourtsis/2ca4eab0056a313c487f457c548bf060 to your computer and use it in GitHub Desktop.
A function that flattens an array
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
// if an array has content join all parts to comma seperated string and splitted to a new array | |
const flatArray = (array) => array.length ? array.join().split(',') : []; | |
flatArray([[1,2,[3]],4]) | |
flatArray([1,2,3,4]) | |
flatArray([1,2,[3,[4,5]],6]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment