question

Erik Gerritse avatar image
0 Likes"
Erik Gerritse asked Mischa Spelt commented

Does the Array.IndexOf() method work for finding the position of another Array?

Hi everyone,

I am trying to use the Array.indexOf() command to check if an array (P) is an element of another array (P_all). When I test this the method always returns -1, even if I have explicitly added P to P_all before. Am I doing something wrong?

arrayarray index
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

anthony.johnson avatar image
2 Likes"
anthony.johnson answered Mischa Spelt commented

Yeah, this doesn't work. We will discuss on our side how/if we should change this. The question we are not sure on is whether the matching should check if the two compared arrays share the same pointer (since arrays are "pass by reference" shared pointers), or if the matching algorithm should check that all array elements are the same. I kind of lean toward the simple shared pointer check, but others here in the office disagree with me.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Erik Gerritse avatar image Erik Gerritse commented ·

Hi Anthony,thanks for answering my question.

I would use this in the following way: I am trying to code an algorithm in FlexScript which iterates a number of times, using the results of the previous iteration as input for the next one. If the input array has already been used before, the algo is stuck in a loop. To avoid this I want to compare the current input to the input arrays used before.

I think that the 'simple shared pointer' method would therefore not be of great use to me.

2 Likes 2 ·
Mischa Spelt avatar image Mischa Spelt commented ·

Suggestion (borrowed from .NET): have the default == operator compare arrays by element, and supply a Variant.referenceEquals(Variant& other) method for "advanced" usage. I think it really reduces the amount of explaining you have to do to users who write something like

if( token.resources == [1, 2, 3] )
{ 
  ... 
}

and wonder why they don't go inside the if.

2 Likes 2 ·