Check order of dates

Run Settings
LanguageJavaScript
Language Version
Run Command
const validation = (values) => { if (typeof values === "object" && !Array.isArray(values) && values !== null) { console.log('object'); } if (Array.isArray(values)) { console.log('array'); } }; const getDate = (dateString) => new Date(dateString).getTime(); const checkDates2 = (dates) => dates .reduceRight( (acc, currentDate, index) => { console.log('Acc: ', acc); console.log('date: ',getDate(currentDate)); console.log('index: ', index); return index === (dates.length - 1) ? acc : acc - getDate(currentDate); }, getDate(dates[dates.length-1]) ) > 0 ? undefined : 'Dates are incorrect. Wrong order'; // validation({ education: [{ // now: true // }, {}, { // now: true // }] // }); // validation(null); // validation([]) console.log(checkDates2(['2019-12-01', '2019-12-10', '2019-12-11', '2019-12-15']));
Editor Settings
Theme
Key bindings
Full width
Lines