Defines a static class UFArray, a utility library with static methods for Array instances.

Methods

  • Adds elements from one array to another.

    Type Parameters

    • T

    Parameters

    • aTarget: T[]

      Array to add to

    • aSource: T[]

      Array to add from

    Returns T[]

    value of aTarget

  • Checks if an array contains a certain value or an object contains a certain key. It is possible to specify multiple values.

    Parameters

    • aList: object | []

      An array (values are checked) or an object (keys are checked)

    • Rest ...aValue: any[]

      One or more values to check

    Returns boolean

    True if the array contains one of the values or the object has a key that matches one of the values.

  • Creates an array filled with a certain value.

    Type Parameters

    • T

    Parameters

    • anItem: T | (() => T)

      Item to fill with or a function that returns a value of the correct type

    • aCount: number

      Number of items

    • Optional anArray: T[]

      Array to use, when missing create a new array.

    Returns T[]

    created array or the value of anArray.

  • Creates an array filled with a sequence of integer numbers.

    Parameters

    • aCount: number

      Number of numbers to fill with

    • aStart: number = 0

      Starting number (default 0)

    • aStep: number = 1

      Stepping size (default 1)

    • Optional anArray: number[]

      Array to use, when missing create a new array.

    Returns number[]

    created array or the value of anArray filled with sequence of integer numbers

  • Finds an item in the array that matched all properties in the aMatch object.

    This method uses the UF.tools.UFObject.equalProperties to compare properties.

    Parameters

    • anArray: object[]

      Array to look trough

    • aMatch: object

      An object with one or more properties that must be matched.

    • anIgnoreCase: boolean = false

      When true with string types ignore casing when comparing, false casing should match

    Returns number

    index of entry or -1 if none was found

  • Gets an item in an array for a certain index. If the index is outside the array boundary, return a default value instead.

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to get item from

    • anIndex: number

      Index of item

    • aDefault: T

      Default value to return if anIndex is outside the valid boundary.

    Returns T

    item or aDefault if anIndex is invalid.

  • Returns a random item from an array.

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to get item from

    Returns T

    random item

  • Removes one or more items from a certain index.

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to remove item(s) from

    • anIndex: number

      Index to start removing at

    • aCount: number = 1

      Number of items

    Returns T[]

    Value of anArray.

  • Removes duplicate entries.

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to go through

    Returns T[]

    anArray with duplicates removed.

  • Removes all occurrences of an item from an array.

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to remove item from

    • anItem: T

      Item to remove

    • Optional aFromIndex: number = 0

      Remove items starting at from this index (0 is first item)

    Returns T[]

    value of anArray

  • Replaces all values that matches aSearchValue with aNewValue.

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to search trough

    • aSearchValue: T

      Value to match

    • aNewValue: T

      Value to replace matching value's with

    • Optional aFromIndex: number = 0

      Starting index

    Returns T[]

    anArray value

  • Replaces an item at a certain index with a new value.

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to replace item in

    • anIndex: number

      Index of item

    • aNewValue: T

      New value to use

    • aCopy: boolean = false

      When true make a copy of the array and then replace the value

    Returns T[]

    The value of anArray

  • Replaces multiple search values with a new value. If a value from aSearchValues is found, it is replaced with the value from aNewValues. For each value in aSearchValues, aNewValues must contain a matching new value (in other words aNewValues contains the same number of elements as aSearchValues).

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to search trough

    • aSearchValues: T[]

      Array of values to find

    • aNewValues: T | T[]

      Array of new values to replace found values with.

    Returns T[]

    anArray value

  • Randomly swaps elements in array, shuffling the contents of the array.

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to shuffle

    • Optional anIterations: number

      Number of times to perform swap. If the value is not set, it will be set to 1.5 * length of the array.

    Returns T[]

    value of anArray

  • Assumes an array contains only numeric values, sorts the array based on the value.

    Parameters

    • anArray: number[]

      Array of numbers

    • Optional aReverse: boolean = false

      When true sort in reverse order.

    Returns number[]

    anArray with sorted items

  • Returns the sum of all values in the number array.

    Parameters

    • anArray: number[]

      Array of numbers

    • aStart: number = 0

      Starting index, default is 0

    • Optional aCount: number

      Count, when missing process all entries in the array

    Returns number

    sum of all values in the array

  • Swaps two elements in an array.

    Type Parameters

    • T

    Parameters

    • anArray: T[]

      Array to update

    • aFirst: number

      Index to first element

    • aSecond: number

      Index to second element

    Returns T[]

    value of anArray

  • Converts all values to int.

    Parameters

    • anArray: any[]

      Array to update

    Returns number[]

    anArray value

  • Converts all values to Number.

    Parameters

    • anArray: any[]

      Array to update

    Returns number[]

    anArray value