Skip to content

Instantly share code, notes, and snippets.

@lai32290
Created October 6, 2020 00:14
Show Gist options
  • Save lai32290/f3e40fe3462163f43eb118c36dd02784 to your computer and use it in GitHub Desktop.
Save lai32290/f3e40fe3462163f43eb118c36dd02784 to your computer and use it in GitHub Desktop.
Medium - Montando seu lanche com Reduce 2
const ingredientes = [ 'pao', 'tomate', 'queijo', 'ovo frito', 'ketchup', 'mostarda', 'pao' ];
const lanche = ingredientes.reduce(function juntarComPao(resultadoAnterior, ingrediente) {
return `${resultadoAnterior}, ${ingrediente}`;
}, 'prato');
console.log(`Aqui está o seu lanche: ${lanche}`);
// Aqui está o seu lanche: prato, 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