Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "array-utils"

Index

Functions

flattenTree

  • flattenTree<T>(array?: T[], key: string | function): T[]
  • Recursively flattens an array by a specific propertyName or property accessor. It does not mutate the items, meaning the items keeps their original child array.

    Type parameters

    • T

    Parameters

    • Default value array: T[] = []

      Array to flatten

    • key: string | function

      Selector for the child property

    Returns T[]

    An flatten array

getRandomEntry

  • getRandomEntry<T>(array: T[], arrayToPopulate?: T[], tryCount?: undefined | number): T
  • Type parameters

    • T

    Parameters

    • array: T[]

      The array from which you want a random entry

    • Optional arrayToPopulate: T[]

      Optional. If provided, the function checks that the returned entry is not already in the arrayToPopulate.

    • Optional tryCount: undefined | number

      The amount of times the function should try to return a unique value (since this method is recursive). Defaults to 5.

    Returns T

    a random entry from a an array

    Based on Math.random()

groupArrayByProperty

  • groupArrayByProperty<T>(array: T[], key: string | function): T[][]
  • Groups an array of items into multiple arrays, grouped by a common property

    Type parameters

    • T

    Parameters

    • array: T[]

      All properties

    • key: string | function

    Returns T[][]

removeDuplicates

  • removeDuplicates<T>(val: T[]): T[]
  • Creates and returns a new array, clearing duplicates with new Set().

    Type parameters

    • T

    Parameters

    • val: T[]

      The array to remove duplicates from

    Returns T[]

    An edited copy of @param val

Generated using TypeDoc