Skip to content

Instantly share code, notes, and snippets.

@thaerlabs
Created July 19, 2016 21:19
Show Gist options
  • Save thaerlabs/0defea809dd5bddb64546758f8595e71 to your computer and use it in GitHub Desktop.
Save thaerlabs/0defea809dd5bddb64546758f8595e71 to your computer and use it in GitHub Desktop.
const input = [[1,2,[3]],4];
function arrFlatten() {
let flat = [];
for (let i = 0; i < arguments.length; i++) {
if (arguments[i] instanceof Array) {
flat.push.apply(flat, arrFlatten.apply(this, arguments[i]));
} else {
flat.push(arguments[i]);
}
}
return flat;
}
console.log(arrFlatten(input));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment