Skip to content

Instantly share code, notes, and snippets.

@panvourtsis
Created October 17, 2018 07:32
Show Gist options
  • Save panvourtsis/2ca4eab0056a313c487f457c548bf060 to your computer and use it in GitHub Desktop.
Save panvourtsis/2ca4eab0056a313c487f457c548bf060 to your computer and use it in GitHub Desktop.
A function that flattens an array
// 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