Created
May 19, 2017 13:40
-
-
Save victoriadrake/af4b84e561821dbefef13e40077f85f3 to your computer and use it in GitHub Desktop.
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) { | |
if (Array.isArray(arr)) { | |
return arr.reduce(function(done,curr){ | |
return done.concat(flatten(curr)); | |
}, []); | |
} else { | |
return arr; | |
} | |
} | |
// [ 1, 2, 3, 4 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you mind formatting the code? :)