Very helpful.
In case anyone comes across the same problem I was having…
I have lists, where each entry of the list is a record:
set tabGoods to {{|style|:"g185", colorCode:"51", colorName:"black"}, {|style|:"g185", colorCode:"51", colorName:"black"}}
And these functions to remove dulicates did NOT work on it. I don’t know why, but they spit the list back out again with the duplicates still in place.
I’m not sure why these don’t work and what I ended up writing does work, but just in case this is useful to anyone, this removes duplicates even when the list items are records:
on removeDuplicateRecords(inputList)
set itemCount to count of items in inputList
set outputList to {}
repeat with anItem from 1 to itemCount
set firstListItem to item anItem of inputList
set occurrenceCount to 0
repeat with anotherItem from 1 to count of items in outputList
set secondListItem to item anotherItem of outputList
if firstListItem is secondListItem then set occurrenceCount to occurrenceCount + 1
end repeat
if occurrenceCount = 0 then copy firstListItem to end of outputList
end repeat
return outputList
end removeDuplicateRecords
This could be painfully slow for large sets of records, I really don’t know. My lists have at most maybe 10-20 records, so it’s not significant. The longest lists I ran it on, it took 127 milliseconds, so it’s not stressing me out, but I’m guessing from that time that it would not scale well to thousands… but at least it works for records.
- t.spoon