Created
April 1, 2019 23:15
-
-
Save m44-io/55f52ea96e86bc76c17aabb69fbc33d7 to your computer and use it in GitHub Desktop.
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 = (arr = [], result = [], depth) => { | |
depth--; | |
for (var i = 0, length = arr.length; i < length; i++) { | |
var value = arr[i]; | |
if (depth > -1 && Array.isArray(value)) | |
flatten(value, result, depth); | |
else | |
result.push(value); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment