Skip to content

Instantly share code, notes, and snippets.

@bryancodesjs
Created March 8, 2023 03:49
Show Gist options
  • Save bryancodesjs/004892b9b1431694103b2a131403eac2 to your computer and use it in GitHub Desktop.
Save bryancodesjs/004892b9b1431694103b2a131403eac2 to your computer and use it in GitHub Desktop.
A brief example of how Array.prototype.reduce() can be used
const transactions = [
{ id: 1, amount: 100 },
{ id: 2, amount: 200 },
{ id: 3, amount: 300 },
{ id: 4, amount: 450 }
]
const useReduce = transactions.reduce((acc, curr) => {
return acc + curr.amount;
},0);
console.log("$" + useReduce.toLocaleString() + " paid");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment