View Full Version : deleting items in one array from another

02-21-2008, 01:11 PM
Very elementary procedure here, but it's got me bamboozled. I'm trying to delete the items in one array from another. Here's where I'm at:
a1 = #(1,2,3,4,5,6,7,8,9)
a2 = #(2,3,6,9)
for j=1 to a2.count do
(deleteItem a1 a2[j])
-- Error occurred in anonymous codeblock
-- Frame:
-- Runtime error: array index must be positive number, got: #(2, 3, 6, 9)
Help, please? Many thanks.

02-21-2008, 01:31 PM
There you go:

a1 = #(1,2,3,4,5,6,7,8,9)
a2 = #(2,3,6,9)
for j=a2.count to 1 by -1 do
deleteItem a1 a2[j]

02-21-2008, 01:52 PM
Does a2 contains indices or values to delete ?
If it contains indices, Kameleon code will work.

If a2 contains values to delete here is the code:

a1 = #(1,2,3,4,9,5,4,6,7,3,8,1,6,2,9)
a2 = #(2,3,6,9)
for j = 1 to a2.count do
while (index = (findItem a1 a2[j])) != 0 do
(deleteItem a1 index)
print a1

02-21-2008, 02:28 PM
Fabulous. Thank you, gentlemen.

CGTalk Moderation
02-21-2008, 02:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.