Quick actions

cmd+k|ctrl+k

Navigation

Languages

Check order of dates

Snippet info

Language

JavaScript

Visibility

public

Author

paulkotov

Created

2019-12-27T10:48:00Z

Updated

2021-06-10T06:08:31.575123Z

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']));
INFO