Array
The SD.Array
module provides utility functions for working with arrays in Lua. This document details each function's purpose, parameters, return values, and usage examples.
Array.IsArray
SD.Array.IsArray(arr)
SD.Array.IsArray(arr)
Purpose: Checks if the provided table is a sequential array without gaps.
Parameters:
arr
(table
): The table to check.
Returns:
(
boolean
): Returnstrue
if the table is an array,false
otherwise.
Usage Example:
Array.Append
SD.Array.Append(arr, value)
SD.Array.Append(arr, value)
Purpose: Appends an element to the end of the array.
Parameters:
arr
(table
): The array to append to.value
(any
): The value to append.
Returns: None.
Usage Example:
Array.RemoveAt
SD.Array.RemoveAt(arr, index)
SD.Array.RemoveAt(arr, index)
Purpose: Removes an element from an array at the specified index.
Parameters:
arr
(table
): The array to remove from.index
(integer
): The index of the element to remove.
Returns: None.
Usage Example:
Array.IndexOf
SD.Array.IndexOf(arr, value)
SD.Array.IndexOf(arr, value)
Purpose: Finds the first index of a value in an array.
Parameters:
arr
(table
): The array to search through.value
(any
): The value to find.
Returns:
(
integer
|nil
): The index of the value, ornil
if not found.
Usage Example:
Array.Reverse
SD.Array.Reverse(arr)
SD.Array.Reverse(arr)
Purpose: Reverses the elements of an array in place.
Parameters:
arr
(table
): The array to reverse.
Returns: None.
Usage Example:
Array.Concatenate
SD.Array.Concatenate(arr1, arr2)
SD.Array.Concatenate(arr1, arr2)
Purpose: Concatenates two arrays into a new array.
Parameters:
arr1
(table
): The first array.arr2
(table
): The second array.
Returns:
(
table
): A new array containing elements from both arrays.
Usage Example:
Array.Filter
SD.Array.Filter(arr, predicate)
SD.Array.Filter(arr, predicate)
Purpose: Filters an array based on a predicate function.
Parameters:
arr
(table
): The array to be filtered.predicate
(function
): The predicate function to determine if an element should be included. Takes an element as an argument.
Returns:
(
table
): A new array containing only elements that satisfy the predicate.
Usage Example:
Array.Map
SD.Array.Map(arr, transform)
SD.Array.Map(arr, transform)
Purpose: Maps an array to a new array based on a transformation function.
Parameters:
arr
(table
): The array to be mapped.transform
(function
): The transformation function applied to each element. Takes an element as an argument.
Returns:
(
table
): A new array containing the results of the transform function.
Usage Example:
Last updated