Skip to content

Instantly share code, notes, and snippets.

@m44-io
Created April 1, 2019 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m44-io/55f52ea96e86bc76c17aabb69fbc33d7 to your computer and use it in GitHub Desktop.
Save m44-io/55f52ea96e86bc76c17aabb69fbc33d7 to your computer and use it in GitHub Desktop.
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