const products = [
{ id: 1, name: "MacBook Pro", category: "Laptop", price: 180000, isAvailable: true, rating: 4.8 },
{ id: 2, name: "Dell Inspiron", category: "Laptop", price: 90000, isAvailable: true, rating: 4.2 },
{ id: 3, name: "Samsung Galaxy S21", category: "Phone", price: 70000, isAvailable: false, rating: 4.5 },
{ id: 4, name: "iPhone 13", category: "Phone", price: 120000, isAvailable: true, rating: 4.7 },
{ id: 5, name: "Sony Bravia", category: "TV", price: 150000, isAvailable: true, rating: 4.6 },
{ id: 6, name: "LG OLED", category: "TV", price: 170000, isAvailable: false, rating: 4.4 },
{ id: 7, name: "Fossil Smartwatch", category: "Watch", price: 25000, isAvailable: true, rating: 4.1 },
{ id: 8, name: "Casio Digital", category: "Watch", price: 5000, isAvailable: true, rating: 4.0 },
{ id: 9, name: "HP Pavilion", category: "Laptop", price: 75000, isAvailable: true, rating: 4.3 },
{ id: 10, name: "Realme 11 Pro", category: "Phone", price: 33000, isAvailable: true, rating: 4.2 }
];
Total price of all products
Total price of only available products
Average rating of all products - total rating
Highest product price
Lowest product price
Count of products in each category ({ Laptop: 3, Phone: 3, ... }) - Hard and Important
// person.name = " Ram";
// acc.product.category; { product : {}} -
// Laptop - 4 - first - 1 and +1
// acc["Laptop"]
// {Laptop : 2}
const count = products.reduce((acc,product) => {
acc[product.category] = acc[product.category] ? acc[product.category] + 1 : 1;
return acc;
},{});
console.log(count);
Total number of available products
Total number of unavailable products
Total price of all "Laptop" products
Count how many products have rating >= 4.5
Find the product with the highest rating - if its difficult lets find the highest rating first.
Find the product with the longest name
Homework - Create at least 5 array of objects similar to above and then for each array of objects, solve at least 8 questions like above.