Yeah, if you didn't need to preserve order it'd be easy to just use a map instead. But since you do...
Here's an approach that searches for and removes the duplicates of each one:
names = ["Matt", "John", "Matt", "John", "Matt",
"John", "Tim", "Jason", "Tim", "Jason"]
idx = 0
while idx < names.len
while true
nextIdx = names.indexOf(names[idx], idx)
if nextIdx == null then break
names.remove nextIdx
end while
idx += 1
end while
print names
Or, here's an approach that copies names to a unique list, only if they're not already in it.
names = ["Matt", "John", "Matt", "John", "Matt",
"John", "Tim", "Jason", "Tim", "Jason"]
uniqueNames = []
for name in names
if uniqueNames.indexOf(name) == null then
uniqueNames.push name
end if
end for
print uniqueNames
Do either of these suit your needs?