Spot the bug JavaScript
1
// Flag an invoice as settled when payments cover the total.
2
function isSettled(payments, total) {3
const paid = payments.reduce((sum, p) => sum + p, 0);
4
return paid === total;
5
}
6
7
console.log(isSettled([0.1, 0.2], 0.3));
8
// expected: true
9
// actual: false (!)