refactor sortByDates to compareDates