-
-
Save simeg/190f3a22436cbd751bb5507e7607cdbd to your computer and use it in GitHub Desktop.
FP in JS 5
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
// A list of fruit, and their price | |
const fruit = [ | |
{name: 'banana', price: 5}, | |
{name: 'apple', price: 3}, | |
{name: 'pear', price: 7} | |
]; | |
// We use reduce() to get the "total price of all fruit" | |
const sumPriceFruit = fruit | |
.reduce((previous, current) => previous + current.price, 0); | |
// Log to see the result | |
console.log(sumPriceFruit); // 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment