In my current project, I am faced with the challenge of comparing dates stored in the format 'Y-M-D H-i-s' within an array to eliminate duplicates and keep a count alongside the original date. The method I am using to compare the dates is shown below:
function compare(a, b){
if(a.getDate() == b.getDate() && a.getMonth() == b.getMonth() && a.getFullYear() == b.getFullYear()){
return true;
}else{
return false;
};
};
Here is how I iterate through the dates in the array:
times.forEach(function(timeOne){
times.forEach(function(timeTwo){
if(compare(timeOne, timeTwo)){
console.log("same");
}else{
console.log("different");
count.push(timeOne);
};
});
});
Unfortunately, the above approach is not working as expected. It removes the first 1619 values without populating the count array, ultimately causing my browser to crash. I am seeking advice on how to resolve this issue or perhaps an alternative method to achieve the desired outcome. Additionally, I am uncertain about how to incorporate the count feature at this point.
Edit ---
Below is the code snippet remaining in the program:
var results = <?php echo $results; ?>,
times = [],
count = [];
results.forEach(function(result){
times.push(new Date(result.time));
});
Lastly, it's important to note that the items array contains close to 30,000 entries. Therefore, I am looking for an optimized solution that can significantly reduce processing time.