Skip to content

Instantly share code, notes, and snippets.

@zorky
Last active August 24, 2019 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zorky/7781e187d00f59cd16223020c22d9a1c to your computer and use it in GitHub Desktop.
Save zorky/7781e187d00f59cd16223020c22d9a1c to your computer and use it in GitHub Desktop.
Reduce d'une liste de dates, renvoie une chaîne de concaténation des dates: date1, date2, ..., dateN
/**
Exemple de reduce d'une liste de dates (dates_obj : [{date: 'date'}, ...]
*/
reduce(row): string {
dates = row.dates_obj.reduce<string>((previousValue, currentValue, currentIndex) => {
let currentDate = `${dp.transform(currentValue.date, 'dd/MM/yyyy')}`;
const { hh, mm } = { hh: dp.transform(currentValue.date, 'HH'), mm : dp.transform(currentValue.date, 'mm')};
if (hh !== '00') {
currentDate = `${currentDate} à ${hh}h${mm}`;
}
return currentIndex === 0 ? currentDate : `${previousValue}, ${currentDate}`;
}, '');
return dates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment