Skip to content

Instantly share code, notes, and snippets.

@christophemarois
Created July 28, 2015 18:37
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 christophemarois/3d7d610bc17bfab2b8ff to your computer and use it in GitHub Desktop.
Save christophemarois/3d7d610bc17bfab2b8ff to your computer and use it in GitHub Desktop.
Recursive-based, dependency-free, vanilla array flattening
function flatten (arr, deep) {
if (deep) arr = arr.map(function(e){
return Object.prototype.toString.call(e) ===
'[object Array]' ? flatten(e, true) : e;
});
arr = Array.prototype.concat.apply([], arr || []);
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment