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

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

thomas_van_de_sande
Not applicable
139 Views
3 Replies
Message 1 of 4

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

thomas_van_de_sande
Not applicable

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?

4981-flexsim-screengrab.png

0 Likes
Accepted solutions (1)
140 Views
3 Replies
Replies (3)
Message 2 of 4

anthony_johnsonT83CM
Autodesk
Autodesk
Accepted solution

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.

Message 3 of 4

thomas_van_de_sande
Not applicable

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.

Message 4 of 4

mischa_spelt
Advisor
Advisor

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.