Hi,
I have two lists:
set theLIST to {"1", "2", "3", "4", "5", "6", "7", "8"}
set sndLIST to {"A", "A", "A", "B", "C", "C", "C", "D"}
I need to combine items from both lists so the final list looks like this:
set shouldLookLikeLIST to {"A", "1", "2", "3", "B", "4", "C", "5", "6", "7", "D", "8"}
I have tried this so far without much success:
set theLIST to {"1", "2", "3", "4", "5", "6", "7", "8"}
set sndLIST to {"A", "A", "A", "B", "C", "C", "C", "D"}
set shouldLookLikeLIST to {"A", "1", "2", "3", "B", "4", "C", "5", "6", "7", "D", "8"}
set sorted to {}
set end of sorted to item 1 of sndLIST
repeat with i from 1 to count of theLIST
set theCNT to count of theLIST
if i < theCNT then
set xx to item (i + 1) of sndLIST
if xx is not equal to item i of sndLIST then
--log xx
set end of sorted to item i of sndLIST
set end of sorted to item i of theLIST
else
set end of sorted to item i of theLIST
end if
end if
end repeat
if item -2 of sndLIST is not equal to last item of sndLIST then
set end of sorted to last item of sndLIST
set end of sorted to item i of theLIST
end if
sorted
--result {"A", "1", "2", "A", "3", "B", "4", "5", "6", "C", "7", "D", "8"}