This is my first post here. I have a little question. Code:
function tableFor(event, journal) {
let table = [0, 0, 0, 0];
for (let i = 0; i < journal.length; i++) {
let entry = journal[i],
index = 0;
if (entry.events.includes(event)) index += 1;
if (entry.squirrel) index += 2; // Why +2?
table[index] += 1;
}
return table;
}
console.log(tableFor("pizza", JOURNAL));
// → [76, 9, 4, 1]
The JOURNAL file can be found here.
My question is that why there is += index. When i run code, It gives me right results of course, but I don't understand why is +2 not +1? I see that +1 gives me wrong result.
Thanks for replying.