I am kind of lost on how to use the letter parameter inside the reduce function. Just doing cur.letter doesnt allow me to use it. Not sure what is causing the issue. I was able to use "letter" outside the reduce function.
The array I am using is really large in data, so I made a mock array which is similar to the array I am using.
calculateForAllLetter(arr, letter) {
return arr.reduce(function(prev, cur) {
return prev + parseInt(cur.letter);
}, 0);
}
const arr = [{
A: 10,
B: 10,
C: 10
}, {
A: 10,
B: 10,
C: 10
}, {
A: 10,
B: 10,
C: 10
}, {
A: 10,
B: 10,
C: 10
}]
const totalGradesA = this.calculateForAllLetter(arr, "A")
console.log(totalGradesA)