Skip to content

Instantly share code, notes, and snippets.

@thiamsantos
Created April 26, 2018 14:29
Show Gist options
  • Save thiamsantos/c3eae2d69a35dc330d19240c3c70d1bb to your computer and use it in GitHub Desktop.
Save thiamsantos/c3eae2d69a35dc330d19240c3c70d1bb to your computer and use it in GitHub Desktop.
eloquent js squirrel journal
function hasEvent(event, entry) {
return entry.events.indexOf(event) !== -1
}
function tableFor(event, journal) {
return journal.reduce(
(table, entry) => {
const hasTheEvent = hasEvent(event, entry)
const isSquirrel = entry.squirrel
if (hasTheEvent && isSquirrel) {
table[3] += 1
return table
}
if (hasTheEvent) {
table[1] += 1
return table
}
if (isSquirrel) {
table[2] += 1
return table
}
table[0] += 1
return table
},
[0, 0, 0, 0]
)
}
console.log(tableFor('pizza', JOURNAL))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment