Get Unique Items In A List


on GetUniqueItems(sourceList)
set itemCount to (get count of items in sourceList)
set compiledList to {}
--get the first item to kick off the list
repeat with x from 1 to itemCount
set itemFound to false
set itemX to item x of sourceList
if x < itemCount then
repeat with y from (x + 1) to itemCount
set itemY to item y of sourceList
if itemY is itemX then set itemFound to true
end repeat
else
repeat with y from 0 to (itemCount - 1)
set itemY to item y of sourceList
if itemY is itemX then set itemFound to true
end repeat
end if
if itemFound is false then
set end of compiledList to itemX
exit repeat
end if
end repeat
--if no items are found
if (get count of items in compiledList) is 0 then
return compiledList
end if
--find the rest of the unique items
repeat with x from 1 to itemCount
set itemFound to false
set itemX to item x of sourceList
set resultCount to (get count of items in compiledList)
repeat with y from 1 to resultCount
set itemY to item y of compiledList
if itemY is itemX then set itemFound to true
end repeat
if itemFound is false then set end of compiledList to itemX
end repeat
return compiledList
end GetUniqueItems