Created
December 3, 2019 06:11
-
-
Save jespr/cd5a2f4fd4a190efe7a2c2d3fde53557 to your computer and use it in GitHub Desktop.
Return the day of the week given an offset in days
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
// dayOffset("Wednesday", 4) | |
// => "Sunday" | |
const dayOffset = (day, offset) => { | |
const days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; | |
if (days.indexOf(day) === -1) { | |
return "😭 Not a valid day, dummy!"; | |
} | |
return days[(days.indexOf(day) + offset) % 7]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment