Options
All
  • Public
  • Public/Protected
  • All
Menu

A set of static methods for working with arrays of simple types. The arrays can be nested, but they do not contain any objects.

Hierarchy

  • Arr

Index

Methods

Static deepCopy

  • deepCopy(arr: any[]): any[]
  • Make a copy of an nD array. If the input is not an array, then just return the same thing. A new array is returned. The input array remains unchanged. If the input array is undefined, an empty array is returned. If the input is s sparse array, then the output will alos be a sparse array.

    Parameters

    • arr: any[]

      The nD array to copy.

    Returns any[]

    The new nD array.

Static deepCount

  • deepCount(arr: any[]): number
  • Counts the number of values in an nD array . The input array remains unchanged. If the input array is undefined, 0 is returned. The input can be a sparse array. Undefined values are ignored. For example, for [1, 2, , , 3], the count will be 3.

    Parameters

    • arr: any[]

      The nD array to count.

    Returns number

    The number of elements in the nD array.

Static deepFill

  • deepFill(arr: any[], value: any): void
  • Fills an nD array with new values (all the same value). The input array is changed. If the input array is undefined, an empty array is returned. The input can be a sparse array.

    Parameters

    • arr: any[]

      The nD array to fill.

    • value: any

      The value to insert into the array.

    Returns void

Static equal

  • equal(arr1: any, arr2: any): boolean
  • Check if two nD arrays are equal (i.e. that all elements in the array are equal, ===.). If the arrays are unequal in length, false is returned. Elements in the array can have any value.

    Parameters

    • arr1: any

      The first value.

    • arr2: any

      The second values.

    Returns boolean

    True or false.

Static flatten

  • flatten(arr: any[], depth?: number): any[]
  • Take an nD array and flattens it. A new array is returned. The input array remains unchanged. For example, [1, 2, [3, 4], [5, 6]] will become [1, 2, 3, 4, 5, 6]. If the input array is undefined, an empty array is returned.

    Parameters

    • arr: any[]

      The multidimensional array to flatten.

    • Optional depth: number

    Returns any[]

    A new 1D array.

Static indexOf

  • indexOf(arr: any[], value: any): number
  • Find the position of the first occurrence of a specified value in an array. The value can be an array (which is not the case for Array.indexOf()). If the value is not found or is undefined, return -1. If the array is null or undefined, return -1.

    Parameters

    • arr: any[]
    • value: any

      The value, can be a value or a 1D array of values.

    Returns number

    The index in the array of the first occurance of the value.

Static make

  • make(length: number, value: any): number[]
  • Make an array of numbers. All elements in the array will have the same value.

    Parameters

    • length: number

      The length of the new array. If length is 0, then an empty array is returned.

    • value: any

      The values in the array.

    Returns number[]

    The resulting array.

Static makeSeq

  • makeSeq(length: number): number[]
  • Make an array of numbers. All elements in the array will be a numerical sequence, 0, 1, 2, 3....

    Parameters

    • length: number

      The length of the new array. If length is 0, then an empty array is returned.

    Returns number[]

    The resulting array.

Static replace

  • replace(arr: any[], old_value: any, new_value: any): void
  • Replace all occurrences of a specified value in an array. The input array is changed. The value can be an array. If the value is not found or is undefined, return -1.

    Parameters

    • arr: any[]

      The array.

    • old_value: any

      The old value to replace.

    • new_value: any

      The new value.

    Returns void

Generated using TypeDoc