Skip to content

Instantly share code, notes, and snippets.

@eduarmreyes
Created June 23, 2017 21:05
Show Gist options
  • Save eduarmreyes/0c0dc9cf1c9e253e2cfb415afe976309 to your computer and use it in GitHub Desktop.
Save eduarmreyes/0c0dc9cf1c9e253e2cfb415afe976309 to your computer and use it in GitHub Desktop.
Array Flatten using Javascript
(function() {
function f_a(a, result = []) {
a.map(function(e) {
if (Array.isArray(e)) {
result.concat(f_a(e, result));
} else {
result.push(e);
}
});
return result;
}
var a = [[1,2,[3]],4];
var b = f_a(a);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment