Created
February 20, 2018 10:48
-
-
Save jonurry/e958edb8109ba85ae231ff4ba82b0c9a to your computer and use it in GitHub Desktop.
5.1 Flattening (Eloquent JavaScript Solutions)
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
// 5.1 Flattening | |
let arrays = [[1, 2, 3], [4, 5], [6]]; | |
console.log(arrays.reduce((array1, array2) => array1.concat(array2))); | |
// → [1, 2, 3, 4, 5, 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
5. Higher-Order Functions
5.1 Flattening
Use the
reduce
method in combination with theconcat
method to “flatten” an array of arrays into a single array that has all the elements of the original arrays.