Skip to content

Instantly share code, notes, and snippets.

@egermano
Created May 23, 2016 04:22
Show Gist options
  • Save egermano/5e39a4208051ec6d9286e17201369b8f to your computer and use it in GitHub Desktop.
Save egermano/5e39a4208051ec6d9286e17201369b8f to your computer and use it in GitHub Desktop.
var flatten = function(a) {
return a.reduce(function (b, c) {
return b.concat(Array.isArray(c) ? flatten(c) : c);
}, []);
};
var input = [[1,2,[3]],4];
var output = flatten(input);
console.log(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment