Start string
let current dates'01/02/2021,09/08/2021,11/22/2021,11/23/2021,12/24/2021,01/02/2022,01/03/2022,09/08/2023,11/22/2024,11/23/2022,12/24/2023,01/02/2025,01/03/2026,09/08/2027'
I need to convert to and array of strings sorted by year:
let closureDates = ['01/02/2021,09/08/2021,11/22/2021,11/23/2021,12/24/2021','01/02/2022,01/03/2022,11/23/2022','09/08/2023,12/24/2023','11/22/2024','01/02/2025','01/03/2026','09/08/2027',
destructClosureDates(closureDatesMultpleYrs)
function destructClosureDates(dates) {
let strDates = dates.split(",")
let strDays = []
let strYears = []
strDates.forEach(day => {
strDays.push(day.split('/'))
})
strDays.forEach(day => {
strYears.push(day[2])
})
let sortedDates = strDates.sort((a, b) => {
a = a.split('/')
b = b.split('/')
return a[2].localeCompare(b[2]);
})
let unqiYears = [...new Set(strYears)]
let sortedUniYears = unqiYears.sort((a, b) => {
return a.localeCompare(b)
})
}
const Lmap = new Map(Object.entries(newArr));
I'm not sure how to loop through the Map and combine the dates strings by year. Do I need to restructure the code in another data structure?