I pretty sure i’m implementing the .reduce method wrong. Can someone tell my what i’m doing wrong?
I’m trying to the sum when a new expense is added to the array and i’m displaying it under the expense category.
line 53
I pretty sure i’m implementing the .reduce method wrong. Can someone tell my what i’m doing wrong?
I’m trying to the sum when a new expense is added to the array and i’m displaying it under the expense category.
line 53
You’re implementing it correctly. The only catch you might be getting - .reduce()
has to have second argument, initial value when called with empty array, otherwise error will be thrown:
const array = [1, 2, 3];
const empty = [];
array.reduce((a, b) => a + b); // 6
empty.reduce((a, b) => a + b); // Error
empty.reduce((a, b) => a + b, 0); // 0