Options
All
  • Public
  • Public/Protected
  • All
Menu

Module array

Utility functions for array.

Index

Functions

filterInPlace

  • filterInPlace<T>(array: T[], filter: (element: T) => boolean): void
  • Filters an array IN PLACE, as opposed to returning a new array.

    Type parameters

    • T

    Parameters

    • array: T[]

      The array to filter, it will be mutated.

    • filter: (element: T) => boolean

      The filter function, return true on elements to keep.

        • (element: T): boolean
        • Parameters

          • element: T

          Returns boolean

    Returns void

isEmpty

  • isEmpty<T>(array: T[]): array is []
  • Checks if an array is empty, and notifies TypeScript that it is if so.

    Type parameters

    • T

    Parameters

    • array: T[]

      The array to check if is empty.

    Returns array is []

    True if empty, false otherwise.

make2D

  • make2D<T>(width: number, height: number, defaultValue: T): T[][]
  • make2D<T>(width: number, height: number): Array<Array<T | undefined>>
  • Creates a 2D array (array of arrays).

    Type parameters

    • T

    Parameters

    • width: number

      The width of the [first] array.

    • height: number

      The height of the [second] arrays in the first.

    • defaultValue: T

      An optional default value to fill in each element in all arrays with.

    Returns T[][]

    A 2D array, all fill in with the default value.

  • Creates a 2D array (array of arrays).

    Type parameters

    • T

    Parameters

    • width: number

      The width of the [first] array.

    • height: number

      The height of the [second] arrays in the first.

    Returns Array<Array<T | undefined>>

    A 2D array, all fill in with undefined.

removeElementFrom

  • removeElementFrom<T>(element: T, ...arrays: T[][]): number
  • Removes a matching element from the array, if present.

    Type parameters

    • T

    Parameters

    • element: T

      The element to remove from arrays.

    • Rest ...arrays: T[][]

      The array(s) you want to try to the element from.

    Returns number

    The number of arrays this element was removed from.

removeElements

  • removeElements<T>(array: T[], ...elements: T[]): number
  • Removes a matching element from the array, if present.

    Type parameters

    • T

    Parameters

    • array: T[]

      The array to attempt to remove an element from.

    • Rest ...elements: T[]

      The element(s) you want to try to remove from the array.

    Returns number

    The number of elements removed.

shuffle

  • shuffle<T>(array: T[], rng: () => number): void
  • Shuffles this array randomly IN PLACE.

    see

    http://stackoverflow.com/a/6274381/944727

    Type parameters

    • T

    Parameters

    • array: T[]

      The array to shuffle IN PLACE.

    • rng: () => number

      A callback that is a random number generator, must generate numbers [0, 1).

        • (): number
        • Returns number

    Returns void

sortedAscending

  • sortedAscending<T>(array: ReadonlyArray<T>, getVal?: undefined | ((element: T) => any)): T[]
  • Returns a newly sorted array of the passed in array. The passed in array is not changed.

    Type parameters

    • T

    Parameters

    • array: ReadonlyArray<T>

      The array to form a sorted one from.

    • Optional getVal: undefined | ((element: T) => any)

      An optional callback to get the value from each item to compare against.

    Returns T[]

    A new array that is the sorted form of the passed in array.

Generated using TypeDoc