Skip to content

Instantly share code, notes, and snippets.

@ekrem-aktas
Created September 24, 2020 12:14
Show Gist options
  • Save ekrem-aktas/b4d745c503851a3a9a51d0b778b0cb4e to your computer and use it in GitHub Desktop.
Save ekrem-aktas/b4d745c503851a3a9a51d0b778b0cb4e to your computer and use it in GitHub Desktop.
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