insertAt

Inserts the given value into the array at the provided index

T[]
insertAt
(
T
)
(
T[] array
,
size_t position
,)

Parameters

array T[]

the array to insert into

position size_t

the position to insert at

value T

the value to insert

Return Value

Type: T[]

the updated array

Examples

Tests inserting into an array at the given index

int[] vals = [];
vals = vals.insertAt(0, 1);
assert(vals == [1]);

vals = vals.insertAt(0, 69);
assert(vals == [69, 1]);

vals = vals.insertAt(1, 68);
assert(vals == [69, 68, 1]);

vals = vals.insertAt(3, 420);
assert(vals == [69, 68, 1, 420]);

// Failure to insert (array stays the same)
vals = vals.insertAt(5, 421);
assert(vals == [69, 68, 1, 420]);

Meta