I have an object that holds the totals of some entities where I need to loop through another array of objects which have some boolean properties I want to check and if true then I want to increment the relevant counter in the totals object.
A simple example of what I'm trying to do is below and works fine as is however I was wondering how I can achieve this in a cleaner way possibly with map/filter/reduce etc. but I would still like to only have to loop through the array once and avoid iterating over it multiple times
const totals = { a: 0, b: 0, c: 0 };
myArr.forEach((val) => {
if (val.condition1) {
totals.a++;
}
if (val.condition2) {
totals.b++;
}
if (val.condition3) {
totals.b++;
}
});