Jump to content
Sign in to follow this  
ConanOfOz

FAQ Error about Arrays

Recommended Posts

I found the following in a FAQ about arrays...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">

...

Other way to use this: remove the third element in an array:

MyArray = MyArray - [MyArray select 2]

...

<span id='postcolor'>

99% of the time, the intended action may in fact be what happens, but the statement is in error, and the result may not be what you expect.  What actually occurs is this...

1. Retreve the value in ordinal position 3 (3rd value) from array MyArray.

2. Place that value within the square brackets (we must subtract a type Array from an Array, this way ensures that happens).

3. DELETE ALL OCCURENCES OF THIS VALUE FROM ARRAY MyArray.

If all the contents of MyArray are unique, then you don't have a problem.  However, if this array can contain duplicate values (there could be all sorts of cases where you want to hold values that may occur more than once in your array) then you come completely unstuck with this command.

Bottom line is, the example command DOES NOT remove the 3rd element of this array.

It DOES remove ALL values which are the same as the value held in the 3rd element of this array.

Share this post


Link to post
Share on other sites

arrayA - arrayB

Operand types:

   arrayA: Array

   arrayB: Array

Type of returned value:

   Array

Description:

   all elements in arrayB removed from arrayA

Example:

   [0, 1, 2, 4, 0, 1, 2, 3, 4, 5] - [1, 2, 3] , result is [0, 4, 0, 4, 5]

It seems to be working. Its how its suppose to work.

-EDIT- Dont trust FAQs, trust the official Command Reference.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×