I’m curious of the best way to detect that an arraycollection contains duplicate objects as determined by an object’s property value. For example,
var _myArrayCollection:ArrayCollection = new ArrayCollection([{name: "name1", value: "value1"}, {name: "name2", value: "value2"}, {name: "name1", value: "value3"}]);
Notice that this arraycollection has 3 items. 2 of the items have the same value for the name property. I would consider this a duplicate.
Any ideas what the body of this method would look like? I have ideas but none of them feel very elegant.
private function containsDuplicates(ac:ArrayCollection, property:String):Boolean
You could save the values of the given property on an array, and keep searching inside that array for duplicates. The only bad part is that search time increases as the array size does.
A more efficient (but very more complex solution) may be to save the values, order them, and do a single run to search for duplicates.