const demoData = [ { imgSrc: "/focus/0.jpg", title: "Petal Styled 18k Silver Plated…
- User
const demoData = [ { imgSrc: "/focus/0.jpg", title: "Petal Styled 18k Silver Plated Necklace Earring Bracelet Rings Jewellery Set", actualPrice: 1500, price: 1200, }, { imgSrc: "/focus/1.jpg", title: "18k gold plated earings", actualPrice: 400, price: 200, }, { imgSrc: "/focus/2.jpg", title: "18k gold plated ring", actualPrice: 100, price: 50, }, ];
sum of all price
- Assistant
To find the sum of the prices in the
demoDataarray, you need to add up thepriceproperty of each object in the array. Here is a calculation:- First item's price: 1200
- Second item's price: 200
- Third item's price: 50
Sum of all prices:
1200 + 200 + 50 = 1450The sum of all prices is 1450.
- User
using js
- Assistant
You can calculate the sum of all prices in the
demoDataarray using JavaScript by utilizing thereducemethod. Here's a code snippet to do that:const demoData = [ { imgSrc: "/focus/0.jpg", title: "Petal Styled 18k Silver Plated Necklace Earring Bracelet Rings Jewellery Set", actualPrice: 1500, price: 1200, }, { imgSrc: "/focus/1.jpg", title: "18k gold plated earings", actualPrice: 400, price: 200, }, { imgSrc: "/focus/2.jpg", title: "18k gold plated ring", actualPrice: 100, price: 50, }, ]; const totalSum = demoData.reduce((accumulator, currentItem) => { return accumulator + currentItem.price; }, 0); console.log("Sum of all prices:", totalSum);This code will output:
Sum of all prices: 1450The
reducemethod iterates over thedemoDataarray, accumulating thepriceof each item, starting with an initial value of0.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.