Created
June 23, 2017 21:05
-
-
Save eduarmreyes/0c0dc9cf1c9e253e2cfb415afe976309 to your computer and use it in GitHub Desktop.
Array Flatten using Javascript
This file contains 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() { | |
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