I understand practically all of this code except the lines noted below
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;
if (hasEvent(event, entry)) index += 1;
if (entry.squirrel) index += 2;
table[index] += 1;
}
return table;
}
console.log(tableFor("pizza", JOURNAL));
// → [76, 9, 4, 1]
JOURNAL
is an array. This function loops through it to find if any of the entries hold the value of pizza, and what the value of the property of squirrel
is. Based on the results of those two checks, 1 is added to one of the 4 index in table
. I guess I'm not understanding what the hasEvent
function does, and how it interacts with the first if
statement.
For more details, code can be found about halfway through this page