function hasEvent(event, entry) {
return entry.events.indexOf(event) != -1;
}
function tableFor(event, journal) {
var table = [0, 0, 0, 0];
for (var i = 0; i < journal.length; i++) {
var entry = journal[i], index = 0; // what is going on here?
if (hasEvent(event, entry)) index += 1;
if (entry.squirrel) index += 2;
table[index] += 1;
}
return table;
}
console.log(tableFor("pizza", JOURNAL));
For the above code - What is the commented section doing? Journal is an array of objects, each with two properties, the first of which is 'events' and contains an array, the second is a boolean. I can see that an object is being accessed and stored in entry for each loop through, but i don't know what the , index=0;
is doing.