Skip to content

Instantly share code, notes, and snippets.

@iagocavalcante
Last active December 20, 2018 10:11
Show Gist options
  • Save iagocavalcante/27f4783c1390fbdfcbced93fc1cc685d to your computer and use it in GitHub Desktop.
Save iagocavalcante/27f4783c1390fbdfcbced93fc1cc685d to your computer and use it in GitHub Desktop.
const usuarios = [
{ nome: 'Aluno 1', parcelasFaltantes: 3, valor: 89.9 },
{ nome: 'Aluno 2', parcelasFaltantes: 5, valor: 19.9 },
{ nome: 'Aluno 1', parcelasFaltantes: 7, valor: 49.9 },
{ nome: 'Aluno 1', parcelasFaltantes: 6, valor: 69.9 },
{ nome: 'Aluno 1', parcelasFaltantes: 2, valor: 99.9 }
]
const totalPorUsuario = usuario =>
usuario.parcelasFaltantes * usuario.valor;
const somatorioTotal = usuarios =>
usuarios.reduce((total, usuario) => total += totaPorUsuario(usuario), 0);
console.log('valor total faltante =>', somatorioTotal(usuarios))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment