Skip to content

Instantly share code, notes, and snippets.

@jonurry
Created February 20, 2018 10:48
Show Gist options
  • Save jonurry/e958edb8109ba85ae231ff4ba82b0c9a to your computer and use it in GitHub Desktop.
Save jonurry/e958edb8109ba85ae231ff4ba82b0c9a to your computer and use it in GitHub Desktop.
5.1 Flattening (Eloquent JavaScript Solutions)
// 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]
@jonurry
Copy link
Author

jonurry commented Feb 20, 2018

5. Higher-Order Functions

5.1 Flattening

Use the reduce method in combination with the concat method to “flatten” an array of arrays into a single array that has all the elements of the original arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment