Skip to content

Instantly share code, notes, and snippets.

@szemate
Last active September 22, 2022 13:39
Show Gist options
  • Save szemate/bed26f96b20cd50bf4b39ead7a3982ae to your computer and use it in GitHub Desktop.
Save szemate/bed26f96b20cd50bf4b39ead7a3982ae to your computer and use it in GitHub Desktop.
JS store accounting exercise
/*
STORE ACCOUNTING
We are writing a program module for an online shop that processes purchases.
The program receives the sold items as an array of objects; each object
contains the name of the item, its price and its category (see below).
1. Print the names and the number (the count) of all sold homeware accessories.
2. Print the total revenue (the sum of the prices of all sold items).
3. Print the average price of the items. Make sure that the price is rounded to 2 decimal points.
4. Print the name of the most expensive product.
*/
const items = [
{ product: "Premier Housewives Stainless Steel Toolset", price: 19.97, category: "homeware" },
{ product: "iChinchin Women's Long Sleeve T Shirt", price: 15.99, category: "clothing" },
{ product: "U-Design Toothbrush Holder Set", price: 10.55, category: "homeware" },
{ product: "Elgar 400W Hand Mixer", price: 25.99, category: "appliances" },
{ product: "Great Gatsby White and Gold Kettle", price: 49.99, category: "homeware" },
{ product: "AM Bristol Men's Fitted Boxers", price: 24.99, category: "clothing" },
{ product: "Disnoy Brittle Small Cookie Jar", price: 10.01, category: "homeware" },
{ product: "Oreal-C Cross Action Electric Toothbrush", price: 22.19, category: "appliances" },
{ product: "Wrundole Designs Duck Wall Clock", price: 34.50, category: "homeware" },
{ product: "RuralComfort Dressing Gown for Men", price: 26.99, category: "clothing" },
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment