Sancho Sancho
Sep 4, 2018 · 1 min read

Maybe I don’t get something, but why not just use good old plain objects?

function getDayName(dayValue) {
const dayNamesMap = {
0: 'Sunday',
1: 'Monday',
2: 'Tuesday',
3: 'Wednesday',
4: 'Thursday',
5: 'Friday',
6: 'Saturday'
};
return dayNamesMap[dayValue] || 'Unknown';
}
function getCurrentDayName() {
return getDayName(new Date().getDay());
}

Also, I have to disagree on always using ternary instead of if, they tend to turn into brainf**k after some nesting depth, no matter what. :)

    Sancho Sancho

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade