Product list with cart solution

Solution retrospective
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
Please log in to post a comment
Log in with GitHubCommunity feedback
- @grgrnkoo
Good job! All nuances are perfectly worked out! Can not find anything that could be upgraded!
Marked as helpful
Join our Discord community
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