const result = (arr) => {
return arr.map((i) => {
if (i.type === 'pineapple') i.price *= 2;
return i;
});
};
const fruits = [
{id: 1, type: 'apple', price: 52},
{id: 2, type: 'apple', price: 76},
{id: 3, type: 'orange', price: 48},
{id: 4, type: 'orange', price: 52},
{id: 5, type: 'apple', price: 32},
{id: 6, type: 'pineapple', price: 52},
{id: 7, type: 'apple', price: 88},
{id: 8, type: 'pineapple', price: 66},
{id: 9, type: 'apple', price: 52},
{id: 10, type: 'pineapple', price: 88},
];
const newFruits = fruits.filter(({ type }) => type !== "apple");
console.log(newFruits);
const result = fruits
.map(fruit => fruit.type === "pineapple"
? {...fruit, price: fruit.price * 2}
: fruit)
.filter(fruit => fruit.type !== "apple")