Last active
January 3, 2017 21:18
-
-
Save jzombie/be96c5f2a17860ff7b141ed50fe06fd2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) { | |
// The reduce() method reduces the array to a single value | |
// @see http://www.w3schools.com/jsref/jsref_reduce.asp | |
return arr.reduce(function (flat, toFlatten) { | |
// The concat() method is used to merge two or more arrays. | |
// This method does not change the existing arrays, but instead returns a new array. | |
// @see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/concat | |
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment