Trying to get _.uniq() working on the following structure:
[
{'x' : 1, 'y': 2},
{'x' : 1, 'y': 2},
{'x' : 2, 'y': 3},
{'x' : 2, 'y': 4},
{'x' : 3, 'y': 4}
]
where the result should be:
[
{'x' : 1, 'y': 2},
{'x' : 2, 'y': 3},
{'x' : 2, 'y': 4},
{'x' : 3, 'y': 4}
]
ie duplicate items removed. I'd like to avoid stringify, because I then just have to parse each back out to a JSON object.
Any help would be appreciated.
EDIT: tring Matt's solution below, I'm missing something I think - this doesn't work. If I log the values for a and b, I see
_.uniq($scope.validNotes, function (a, b) {
console.log(a, b);
return a.x === b.x && a.y === b.y;
});
Object {x: 2, y: 3} 0
Object {x: 1, y: 0} 1
Object {x: 2, y: 3} 2
Object {x: 3, y: 2} 3
Object {x: 4, y: 2} 4
Object {x: 5, y: 1} 5
Which obviously means I'll never find any dupes