Created
May 9, 2017 01:36
-
-
Save granmoe/4b4a7ef0f7cacf511221413342c5e523 to your computer and use it in GitHub Desktop.
Returns a message describing the time of day given a start and end hour. A small and humble chunk of code, but I thought my approach was kind of nifty.
This file contains 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 getTimeOfDay (start, end) { | |
if (start < 12 && end > 16) { return null } // not specific enough | |
// we don't care about the window from 22:00 - 06:00 | |
const timesOfDay = Array(24) | |
.fill('Morning', 6, 12) | |
.fill('Afternoon', 12, 16) | |
.fill('Evening', 16, 22) | |
return Array.from(new Set(timesOfDay.slice(start, end))) | |
.filter(value => !!value) | |
.join(' / ') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment