-
-
Save digitalconceptvisuals/ccb41b352d92c7601981b1f6628c5c4e to your computer and use it in GitHub Desktop.
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 dayName(day) { | |
// Use an array instead of switch | |
const dayNames = | |
["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; | |
// Is the day value between 1-7? | |
if (day < 1 || day > 7) | |
throw 'Invalid day number'; | |
// Array starts with 0, Mon->1 | |
return dayNames[day-1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment