Created
December 3, 2019 11:09
-
-
Save iamshadmirza/ac3a775233bbb90d86a0021849229b01 to your computer and use it in GitHub Desktop.
Solution of weekly problem from Cassidy Williams's Newsletter
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
// Interview question of the week by Cassidy Williams's Newsletter | |
// This week's question courtesy of Louis: | |
// Write a function that takes the name of a day (e.g "Monday", "Tuesday") | |
// and an integer offset, and returns the name of the day which would be the original + offset. | |
// Extra credit: do it in 1 line! | |
// Example: | |
// > dayOffset("Wednesday", 4) | |
// > "Sunday" | |
dayOffset(day, offset) { | |
const week = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'sunday']; | |
return week[(week.findIndex(weekday => weekday === day.toLowerCase()) + offset) % 7]; | |
} | |
console.log(dayOffset("Wednesday", 4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment