Created
April 26, 2018 14:29
-
-
Save thiamsantos/c3eae2d69a35dc330d19240c3c70d1bb to your computer and use it in GitHub Desktop.
eloquent js squirrel journal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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