Generation

generate functionThu, 08 Dec 2022

const products = [{name :"a", quantity:5}, {name :"c", quantity:3} ] make a function to find by name and increment the quantity. Must be imutable. Must return the updated products array.

function findAndUpdate(products, name){ return products.map(function(product){ if (product.name === name){ product.quantity += 1; } return product; }); }

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant