Created
July 28, 2015 18:37
-
-
Save christophemarois/3d7d610bc17bfab2b8ff to your computer and use it in GitHub Desktop.
Recursive-based, dependency-free, vanilla array flattening
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, 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