Skip to content

Instantly share code, notes, and snippets.

@jespr
Created December 3, 2019 06:11
Show Gist options
  • Save jespr/cd5a2f4fd4a190efe7a2c2d3fde53557 to your computer and use it in GitHub Desktop.
Save jespr/cd5a2f4fd4a190efe7a2c2d3fde53557 to your computer and use it in GitHub Desktop.
Return the day of the week given an offset in days
// 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