Skip to content

Instantly share code, notes, and snippets.

@C-Rodg
Created November 4, 2016 01:31
Show Gist options
  • Save C-Rodg/707c649d4e0946d4332e78cb0ed56af7 to your computer and use it in GitHub Desktop.
Save C-Rodg/707c649d4e0946d4332e78cb0ed56af7 to your computer and use it in GitHub Desktop.
A method for recursively flattening an array using a closure.
function flatten(input) {
var out = [];
var loop = function(arr) {
return arr.map.((val) => {
return Array.isArray(val) ? loop(val) : out.push(val);
});
};
loop(input);
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment