Notifications
Clear all

[Closed] deleting items in one array from another

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.

3 Replies

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] 
)

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

Fabulous. Thank you, gentlemen.