Reduce Object Data
Reduce Object Data
reduce is useful when each item contributes part of one final value. With cart lines, each item contributes its price multiplied by its quantity.
The accumulator should represent the total so far. Each callback call returns the next total for the following item.
Your task: Complete calculateCartTotal so it returns the full cart total. The function should return 0 for an empty cart.
Free with a JS Exercises account
Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.
By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.
Reduce Object Data
reduce is useful when each item contributes part of one final value. With cart lines, each item contributes its price multiplied by its quantity.
The accumulator should represent the total so far. Each callback call returns the next total for the following item.
Your task: Complete calculateCartTotal so it returns the full cart total. The function should return 0 for an empty cart.