I am trying to take a report of class meeting days in abbreviated form. Each row has an array of days (M,T,W,TH,F,S,SU). How could I loop through the array and change each value of:
M to Monday T to Tuesday W to Wednesday TH to Thursday F to Friday S to Saturday SU to Sunday
I would like to keep the array intact. To switch from {M,W,F} to {Monday,Wednesday,Friday}.
I have tried to for loop through and use a switch in the loop with no luck.
Can you help?
I would use a constant map to help me translate from short to long.
Like this:
const DAYS_SHORT_TO_LONG = {
SU: 'Sunday',
M: 'Monday',
T: 'Tuesday',
W: 'Wednesday',
TH: 'Thursday',
F: 'Friday',
S: 'Saturday',
}
const daysToConvert = ['M', 'SU', 'F', 'TH'];
const result = daysToConvert.map((shortDay) => DAYS_SHORT_TO_LONG[shortDay]);
console.log(result);