Page MenuHomeFeedback Tracker

[Feature Request] New scripting command for arrays: insert/insertAt
Feedback, NormalPublic

Description

Places an element at a specific index of an array:

_array = [1,2,4];
_index = 0;
_value = 0;
_array insert [_index, _value]; //[0,1,2,4];
_index = 3;
_value = 3;
_array insert [_index, _value]; //[0,1,2,3,4]

_array insert [6, "outOfBounds"]; //[0,1,2,3,4,nil,"outOfBounds"]

or maybe it could work like append:

_array = [];
_index = 0;
_values = [1,2,3];
_array insert [_index, _values];//[1,2,3];

alternative name: insertAt

maybe the command could support strings too?

Details

Severity
None
Resolution
Open
Reproducibility
N/A
Operating System
Windows 7
Category
General

Event Timeline

Leopard20 created this task.Dec 3 2020, 5:10 PM
Leopard20 updated the task description. (Show Details)Dec 3 2020, 5:18 PM
Leopard20 updated the task description. (Show Details)
Leopard20 renamed this task from [Feature Request] New scripting command for arrays: insert to [Feature Request] New scripting command for arrays: insert/insertAt.Dec 3 2020, 5:46 PM
Leopard20 updated the task description. (Show Details)
Leopard20 updated the task description. (Show Details)
Leopard20 updated the task description. (Show Details)Dec 3 2020, 5:48 PM
dedmen added a subscriber: dedmen.Dec 7 2020, 6:52 PM

-1 index for "at end"
you could just use append for that, but I can either just support it, or add checking and error for negative index.

dedmen added a comment.Dec 7 2020, 7:15 PM
_array = []; 
_array insert [-1, [1,2,4]]; //[0,1,2,4]; 
_index = 0; 
_value = 0; 
_array insert [_index, [_value]]; //[0,1,2,4]; 
_index = 3; 
_value = 3; 
_array insert [_index, [_value]]; //[0,1,2,3,4] 
 
_array insert [6, ["outOfBounds"]];

_array

[0,1,2,3,4,<null>,"outOfBounds"]

dedmen added a comment.Dec 7 2020, 7:20 PM

string insert will be padded with whitespace if you go past end

dedmen added a comment.EditedDec 7 2020, 8:34 PM
"test" insert [-1, "ab"] // "testab"
"test" insert [1, "ab"] // "tabest"
"test" insert [0, "ab"] // "abtest"
dedmen claimed this task.Dec 7 2020, 8:34 PM
dedmen changed the task status from New to Assigned.
dedmen set Ref Ticket to AIII-53636.
dedmen changed the task status from Assigned to Feedback.Dec 9 2020, 2:02 PM