array comparison

does anyone know if there is an easier way to do get the difference between two arrays
heres what I have


set Array1 to {"a", "b", "c", "d"}
set Array2 to {"a", "b", "c"}
set Difference to {}
repeat with anitem in Array1
	if anitem is not in Array2 then
		set Difference to Difference & return & anitem
	end if
end repeat

Don’t know that this is “easier” or not, but a slightly different approach.

set Array1 to {"a", "b", "c", "d", 1}
set Array2 to {"a", "b", "c"}
set Difference to {}
if (count of Array1) is greater than or equal to (count Array2) then
	repeat with anItem in Array1
		if anItem is not in Array2 then set Difference's end to contents of anItem
	end repeat
else
	repeat with anItem in Array2
		if anItem is not in Array1 then set Difference's end to contents of anItem
	end repeat
end if
return Difference

PreTech

Hi,

it’s very easy using List & Record Tools

set Array1 to {"a", "b", "c", "d"}
set Array2 to {"a", "b", "c"}
set Difference to difference of Array1 and Array2
--> {"d"}

Whoa! Now that’s easy!:o

I thought I had seen something like that before.

PreTech

yes that would be but for some reason I can’t seem to get that to work I don’t have Satimage Scripting Additions on my lt but I do on the G5 and don’t even see anything in the dict for difference. maybe I need the addtion upgraded?

I just installed Satimage and it doesn’t have the difference command in it. For arrays and lists it deals only with real numbers it seems.

PreTech

I’m terribly sorry, I mixed the additions up

Here are the right ones

http://osaxen.com/files/listamprecordtools1.0.5.html

Thanks StefanK,

I just found the correct osax before you posted.

PreTech