Skip to content

Instantly share code, notes, and snippets.

@lai32290
Created October 6, 2020 00:16
Show Gist options
  • Save lai32290/1402336d8acce5b94fa68efff8b8c519 to your computer and use it in GitHub Desktop.
Save lai32290/1402336d8acce5b94fa68efff8b8c519 to your computer and use it in GitHub Desktop.
Medium - Montando seu lanche com Reduce 3
const matriz = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ];
const valorInicial = [];
const vetor = matriz.reduce(function achatar(resultadoAnterior, lista) {
return [ ...resultadoAnterior, ...lista ];
}, valorInicial);
console.log(vetor);
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment