NI TestStand Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
stephenb2

Last element in array by -1 index

Status: New

Return the last element of an array by indexing it with -1, as in myArray[-1].

 

For a bonus, the second-to-last could be returned by usinging index -2, etc.

5 Comments
RavensFan
Knight of NI
crossrulz
Knight of NI

But this is the TestStand Idea Exchange, not the LabVIEW IE.  Therefore, not a duplicate.

 

But those arguments against this idea are still valid.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
dug9000
NI Employee (retired)

TestStand supports negative array bounds though so this would not be possible without breaking backwards compatibility. Also, -1 is sometimes used for uninitialized index variables in which case a user might prefer to have teststand give an error to help them catch bugs in their code rather than have it give them the last element when that's not what they intended.

warren_scott
Active Participant

I think that (someone else might have to keep me honest here) TS is still missing reverse() as it pertains to arrays -- whether I can reverse a 1D array.  If reverse() was implemented (also important because 50% of the time I sort an array it will come out backwards) then you could use positive indexes against reversed arrays (might be a little slower, but doable).

RavensFan
Knight of NI

Crossrulz,

 

You're right.  I didn't realize I wasn't in the LabVIEW exchange.