Skip to content

Instantly share code, notes, and snippets.

@cky
Created June 12, 2016 15:50
Show Gist options
  • Save cky/db218f63441e292fabf50d03c0f1b722 to your computer and use it in GitHub Desktop.
Save cky/db218f63441e292fabf50d03c0f1b722 to your computer and use it in GitHub Desktop.
One way to flatten in ES6, not necessarily the best
function flatten(x) {
var result = [];
var appendToResult = function (xs) {
result.splice(result.length, 0, ...xs);
}
if (Array.isArray(x)) {
x.map(flatten).forEach(appendToResult);
} else {
result.push(x);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment