I have this piece of code where I am currently checking for duplicates using the isDuplicate boolean. However, I now want to enhance my code by comparing another property called colorId and then setting the isBigger property for the larger one :) Do you have any suggestions on how I can achieve this? Thank you in advance!
Below is the snippet of code:
$scope.verifyDuplicate = function() {
var names = [{
"order": 1,
"name": "a",
"shortName": "a",
"isDuplicate": false,
"categoryId": 15070,
"colorId": 50
}, {
"order": 2,
"name": "s",
"shortName": "s",
"categoryId": 15071,
"colorId": 51
}, {
"order": 3,
"name": "h",
"shortName": "g",
"focused": 1513262627570,
"isDuplicate": true,
"categoryId": 15074,
"colorId": 54
}, {
"order": 4,
"name": "h",
"shortName": "h",
"isDuplicate": true,
"categoryId": 15075,
"colorId": 59
}];
var sorted, i;
sorted = names.concat().sort(function(a, b) {
if (a.name > b.name)
return 1;
if (a.name < b.name)
return -1;
return 0;
});
for (i = 0; i < names.length; i++) {
if (sorted[i].name !== '') {
sorted[i].isDuplicate = ((sorted[i - 1] && sorted[i - 1].name === sorted[i].name)) || ((sorted[i + 1] && sorted[i + 1].name === sorted[i].name));
}
}
};