niknaks.arrays

- New feature added
This commit is contained in:
Tristan B. Velloza Kildaire 2024-05-10 15:22:44 +02:00
parent da8ae74db6
commit 88d3208718
1 changed files with 16 additions and 2 deletions

View File

@ -484,8 +484,18 @@ unittest
assert(numbas == [1, 2]);
}
/**
* Inserts the given value into
* the array at the provided index
*
* Params:
* array = the array to insert
* into
* position = the position to
* insert at
* value = the value to insert
* Returns: the updated array
*/
public T[] insertAt(T)(T[] array, size_t position, T value)
{
if(position > array.length)
@ -517,6 +527,10 @@ public T[] insertAt(T)(T[] array, size_t position, T value)
}
}
/**
* Tests inserting into an array
* at the given index
*/
unittest
{
int[] vals = [];