Created
February 24, 2018 10:23
-
-
Save JaeYeopHan/54d1c4fb55f2a94c90012c18d56d88d0 to your computer and use it in GitHub Desktop.
JavaScript function utils - Deep Flatten
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 flatten(arr) { | |
return function f(arr, newArr) { | |
arr.forEach(function(v)) { | |
Array.isArray(v) ? f(v, newArr) : newArr.push(v); | |
}); | |
return newArr; | |
}(arr, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment