Created
April 25, 2016 15:23
-
-
Save TheBox193/47fcf5cdf3074ddfc0b2c57617c7448d 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
/** | |
* Recursivly flatten a deeply nested array | |
* @arr Array Array with nested values | |
* @return Array Flattend array | |
*/ | |
function flatten(arr) { | |
return arr.reduce(function(result, current) { | |
if (current instanceof Array) { | |
return result.concat(flatten(current)); | |
} else { | |
result.push(current); | |
return result; | |
} | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment