Options
All
  • Public
  • Public/Protected
  • All
Menu

Module array

Functions

filledWith

  • filledWith<T>(length: number, value: T | SyncFunction<void, T>, opts?: FilledWithOptions): T[]
  • Creates a new array which contains the given value.

    Type parameters

    • T

      Elements type.

    Parameters

    • length: number

      Number of elements.

    • value: T | SyncFunction<void, T>

      Value to fill with. For dynamical filling, provide a function.

    • Optional opts: FilledWithOptions

      Fill options.

    Returns T[]

    Filled array.

filterAsync

  • filterAsync<T>(array: T[], predicate: UnaryPredicateAsync<T>, concurrency?: ConcurrencyType): Promise<T[]>
  • Filter array asynchronously.

    Type parameters

    • T

      Elements type.

    Parameters

    • array: T[]

      Initial array.

    • predicate: UnaryPredicateAsync<T>

      Async predicate.

    • concurrency: ConcurrencyType = ...

      Filtering concurrency.

    Returns Promise<T[]>

    Filtered elements.

peek

  • Peek last item from array.

    throws

    When array is empty.

    Type parameters

    • T

    Parameters

    • array: T[]

      Array with elements.

    • position: PeekPosition = ...

      Peek position.

    Returns T

    Array element.

randomElement

  • randomElement<T>(array: T[]): T
  • Extract a random element from the given array.

    Type parameters

    • T

      Elements type.

    Parameters

    • array: T[]

      Source data array.

    Returns T

    Random element.

remove

  • remove<T>(array: T[], predicate: UnaryPredicate<T>, inPlace?: boolean, firstOccurrence?: boolean): T[]
  • Removes element from array.

    Type parameters

    • T

      Elements type.

    Parameters

    • array: T[]

      Initial array.

    • predicate: UnaryPredicate<T>

      Predicate function to mach needed element.

    • inPlace: boolean = true

      Whether to remove elements from the original array. When false will create a clone and removal will be made from that clone.

    • firstOccurrence: boolean = true

      Whether to remove the first, or all of the occurrences of the found element.

    Returns T[]

    Array with removed elements.

removeInPlace

  • removeInPlace<T>(array: T[], item: T): boolean
  • Removes an item in place from array

    Type parameters

    • T

    Parameters

    • array: T[]

      Array from where to remove.

    • item: T

      Item to remove.

    Returns boolean

    Boolean which indicates whether item was removed.

shuffle

  • shuffle<T>(arr: T[]): T[]
  • Shuffle the given array in-place.

    Type parameters

    • T

      Elements type.

    Parameters

    • arr: T[]

      Initial array.

    Returns T[]

    Same array, but shuffled.

unique

  • unique<T>(array: T[]): T[]
  • Creates a new array which contains unique items.

    Type parameters

    • T

      Elements type.

    Parameters

    • array: T[]

      Input array.

    Returns T[]

    Array with unique items.