I am performing an Array.sort
with the compare method like so:
orderNotes(notes){
function compare(a, b) {
const noteA =a.updatedAt
const noteB =b.updatedAt
let comparison = 0;
if (noteA < noteB) {
comparison = 1;
} else if (noteA > noteB) {
comparison = -1;
}
return comparison;
}
return notes.sort(compare)
}
Now since I need to sort the array anyway and loop through each element with the Array.sort
, I want to use this chance to check if the note.id
matches on the neighboring note, and remove the duplicate from the array (doesn't matter which one). This will save me the trouble to loop again just to check duplication.
Is it possible to alter the array inside the compare()
function and remove the duplicate?
Best