Skip to content

Instantly share code, notes, and snippets.

@lai32290
Created October 6, 2020 00:13
Show Gist options
  • Save lai32290/75466c625d6f1b7a12eb6833c8bf3beb to your computer and use it in GitHub Desktop.
Save lai32290/75466c625d6f1b7a12eb6833c8bf3beb to your computer and use it in GitHub Desktop.
Medium - Montando seu lanche com Reduce 1
const ingredientes = [ 'pao', 'tomate', 'queijo', 'ovo frito', 'ketchup', 'mostarda', 'pao' ];
const lanche = ingredientes.reduce(function juntarComPao(resultadoAnterior, ingrediente) {
return `${resultadoAnterior}, ${ingrediente}`;
});
console.log(`Aqui está o seu lanche: ${lanche}`);
// Aqui está o seu lanche: , pao, tomate, queijo, ovo frito, ketchup, mostarda, pao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment