Last active
August 24, 2019 10:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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