Created
September 24, 2020 12:14
-
-
Save ekrem-aktas/b4d745c503851a3a9a51d0b778b0cb4e to your computer and use it in GitHub Desktop.
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 basket = [ | |
{ name:"apple", type: "fruit" }, | |
{ name:"broccoli", type: "vegetable" } | |
]; | |
// Add prices to each food in the basket | |
const basketWithPrices = basket.reduce((acc, food) => acc.concat({ ...food, price: getPrice(food) }), []); | |
// But Array.map is better for it | |
const basketWithPrices = basket.map(food => ({ ...food, price: getPrice(food)})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment