Created
March 8, 2023 03:49
-
-
Save bryancodesjs/004892b9b1431694103b2a131403eac2 to your computer and use it in GitHub Desktop.
A brief example of how Array.prototype.reduce() can be used
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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