Hi everyone,
I have a script (below) that searches in lists and leaves a result with all names (no duplicates) and their latest message. The problem is that the list starts searching in the beginning and not at the end. I know I have to use some “-” (negative) characters here and there but I can’t figure it out. Any help ? I want it to return {“Mark”, “My Last Message”, “Adam”, “My First Message”, “Jim”, “”}
set AllNames to {"Mark", "Jim", "Adam"}
set UsedNames to {"Mark", 2, 3, 4, "My First Message", "Adam", 2, 3, 4, "My First Message", "Mark", 2, 3, 4, "My Last Message"}
set LastMessages to {}
repeat with i from 1 to ((count UsedNames) / 5) -- I think this has to be repeat with i from -((count UsedNames) / 5) to -1 ?
if AllNames contains (item (((i - 1) * 5) + 1) of UsedNames) and LastMessages does not contain (item (((i - 1) * 5) + 1) of UsedNames) then
set end of LastMessages to (item (((i - 1) * 5) + 1) of UsedNames)
set end of LastMessages to (item (i * 5) of UsedNames)
end if
end repeat
(*This Part Works Fine*)
repeat with i in AllNames
if LastMessages does not contain i then
set end of LastMessages to i as text
set end of LastMessages to ""
end if
end repeat
LastMessages --> {"Mark", "My First Message", "Adam", "My First Message", "Jim", ""}
Thanks in advance