Created
March 29, 2022 09:13
-
-
Save drblue/f4bfb149f1f71216f77a6cc40a265ba4 to your computer and use it in GitHub Desktop.
Array reduce + map
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 products = [ | |
{ name: "Product 1", price: 42 }, | |
{ name: "Product 2", price: 20 }, | |
{ name: "Product 3", price: 1337 }, | |
]; | |
const totalValue = products | |
.filter(product => product.price > 30) | |
.reduce( (sum, product) => { | |
return sum + product.price | |
}, 0 ) | |
console.log("totalValue:", totalValue) | |
const productNames = products.map(product => `<p>${product.name}</p>`) | |
console.log("productNames:", productNames) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment