Page MenuHomeFeedback Tracker

[Feature Request] Using -1 to select the last element in arrays
Feedback, NormalPublic

Description

I think it would be very helpful to allow -1 to select the last array element.
It should only be used by select and #, not param (to not break backward compatibility):

_arr = [1,2,3];
_arr#-1 // return 3

Alternatively, maybe using negative numbers should be just modded in general? (using: count-(-index % count), where count > 0 and index < 0)
e.g.:

_arr = [0, 1, 2, 3, 4];
_arr#-1;    //4
_arr#-2;    //3
_arr#-103 //2

Details

Severity
Feature
Resolution
Open
Reproducibility
N/A
Operating System
Windows 10 x64
Category
Scripting

Event Timeline

Leopard20 renamed this task from [Feature Request] Using -1 to select the last index in arrays to [Feature Request] Using -1 to select the last element in arrays.
Leopard20 updated the task description. (Show Details)Mon, Jul 25, 6:46 PM
Leopard20 updated the task description. (Show Details)
Leopard20 updated the task description. (Show Details)Mon, Jul 25, 6:49 PM
Leopard20 updated the task description. (Show Details)Mon, Jul 25, 6:55 PM

rev 149734 negative index is supported by select and set

BIS_fnc_KK removed BIS_fnc_KK as the assignee of this task.Mon, Jul 25, 8:15 PM
BIS_fnc_KK changed the task status from New to Feedback.
BIS_fnc_KK added a subscriber: BIS_fnc_KK.

# is not supported?

Any particular reason why? I mean # is used more often than select nowadays...
And I can't think of any limitations either 🤔

Why does it not have all the overloads select has?

I don't know, but as far as I see there is no good reason. You could just as easily have all the select overloads, such as _string # [1,2]. Same way you could have _string + [1,2] (I know, it's not a valid syntax)
And - is a unary command, so _arr#-_index is not gonna be confusing either.