Skip to content

Instantly share code, notes, and snippets.

@roppa
Created January 21, 2016 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roppa/fcaf2e7dce629ce03465 to your computer and use it in GitHub Desktop.
Save roppa/fcaf2e7dce629ce03465 to your computer and use it in GitHub Desktop.
Flatten a multi dimentional array
const flatten = (...args) => {
let result = [];
args.forEach(arg => {
if (Array.isArray(arg)) {
arg.forEach(element => {
if (Array.isArray(element)) {
result = result.concat(flatten(element));
} else {
result.push(element);
}
});
} else {
result.push(arg);
}
});
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment