I'm using MultipleDatePicker to select multiple date in year. I add a checkbox that when checked it will select all sunday in calendar.
I have a problem when unchecked it. It doesn't remove all selected sunday in calendar. I have compared by using getTime() as shown in the code below:
var selected = $scope.selectedDates;
for (var i = 0; i < $scope.selectedDates.length; i++) {
var date1 = new Date(selected[i]).getTime();
console.log('date1[' + i + '] = ' + date1 + ' ' + moment($scope.selectedDates[i], 'MM-DD-YYYY'));
for (var j = 0; j < sundays.length; j++) {
var date2 = new Date(sundays[j]).getTime();
console.log('date2[' + j + '] = ' + date2 + ' ' + moment(sundays[j], 'MM-DD-YYYY'));
if (date1 === date2) {
selected.splice(i, 1);
break;
}
}
}
Some are the same and some are not. What's wrong with the code?
Here is the plunker to show the problem.
.isSamefor comparing momentJS objects.. current code looks cluttered a bit.