I have got an array of days:
let days = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ]
Obviously the keys above are from 0 - 6. I use these days to generate a list, a user can then selecte and deselect days from this list. So if they deselect Monday and then select Sunday I now have a selected
array:
let selected = [ 'sunday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday' ]
I then want to format the selected dates and display it to the user, but of course using the code below I will get Sunday - Saturday, when really I want Tuesday - Sunday.
let dayOne = this.selected[0];
let dayTwo = this.selected[this.selected.length - 1];
if (dayOne === undefined && dayTwo === undefined) return;
return dayOne.charAt(0).toUpperCase() + dayOne.slice(1) + ' - ' + dayTwo.charAt(0).toUpperCase() + dayTwo.slice(1);
What's a nice and clear way to do this?