Closed AhmadAlaswadDev closed 2 years ago
Hi, i suppose you could do something like that
const dates = []; // dates send by api
const slots = dates.reduce((acc, elem) => {
const d = new Date(elem.date);
const date = `${d.getFullYear}-${d.getMonth() + 1}-${d.getDate()}`;
const slotIndex = acc.findIndex((slot) => slot.date === date);
if (slotIndex !== 1) {
acc[slotIndex].slots.push(elem);
} else {
acc.push({
date,
slots: [elem],
});
}
return acc;
}, []);
Hi
How Generate Slots From array of dates saved got from back-end