Submitted over 1 year agoA solution to the Product list with cart challenge
Product list with cart solution
react
@amjadsh97

Solution retrospective
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
Code
Loading...
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on Amjad Shadid's solution.
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