Repair a cart total
Take your time, follow the code and check your understanding.
The codeAPI transformations
Example checks
INPUT
[
{
"price": 5,
"quantity": 2
},
{
"price": 3,
"quantity": 1
}
]EXPECTED13
INPUT
[]EXPECTED
0
Your answer5 min · no timer
Implement solve(rows) and return a value. The example checks are visible. JavaScript runs in an isolated, network-blocked worker with a 2-second limit.
Show solution and explanation
Multiply price by quantity before adding each line total.
function solve(rows) {
return rows.reduce((sum, row) => sum + row.price * row.quantity, 0);
}