grgrnkoo• 520
@grgrnkoo
Posted
Good job! All nuances are perfectly worked out! Can not find anything that could be upgraded!
Marked as helpful
0
P
Amjad Shadid• 770
@amjadsh97
Posted
Thank you@grgrnkoo
0
What are you most proud of, and what would you do differently next time?
I learned how to handle product counts, unique product lists, and total price calculations in a shopping cart context using JavaScript. Here's a breakdown of what I implemented:
// Calculate the count of each product
const productCounts = selectedProducts.reduce((acc, product) => {
acc[product.name] = (acc[product.name] || 0) + 1;
return acc;
}, {} as Record);
// Create a list of unique products with their counts
const uniqueProducts = selectedProducts.reduce((acc: Product[], product) => {
if (!acc.find(p => p.name === product.name)) {
acc.push(product);
}
return acc;
}, []);
// Calculate total price
const totalPrice = selectedProducts.reduce((acc, product) => acc + product.price, 0);
### What specific areas of your project would you like help with?
I want feedback on state management
@grgrnkoo
Posted
Good job! All nuances are perfectly worked out! Can not find anything that could be upgraded!
Marked as helpful
@amjadsh97
Posted
Thank you@grgrnkoo
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord