Created
November 4, 2016 01:31
-
-
Save C-Rodg/707c649d4e0946d4332e78cb0ed56af7 to your computer and use it in GitHub Desktop.
A method for recursively flattening an array using a closure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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