Options
All
  • Public
  • Public/Protected
  • All
Menu

Module array

Index

Functions

binarySearch

  • binarySearch<T>(array: T[], predict: (i: T) => boolean, onward: (i: T) => boolean, start?: number, end?: number): [T, number] | null
  • Perform binary search on a sorted array. Element will be fed to predict function, if true, the target is found and returned, otherwise onward function is called and the returned value determins the next move: true - left-ward continuance false - right-ward continuance

    null is returned if none is suitable

    export

    Type parameters

    • T

    Parameters

    • array: T[]
    • predict: (i: T) => boolean
        • (i: T): boolean
        • Parameters

          • i: T

          Returns boolean

    • onward: (i: T) => boolean
        • (i: T): boolean
        • Parameters

          • i: T

          Returns boolean

    • start: number = 0
    • Optional end: number

    Returns [T, number] | null

    result and its index, null if not found

deepMap

  • deepMap(deepArray: any[], iteratee: (item: any, cord: number[], index: number) => any, pos?: number[], index?: any): any
  • Like flatMap, this function walks through the nested(multi-dimension) array. This function keep the original dimension. e.g.: deepMap([1, [2, 3]], x => x + 1) => [2, [3, 4]]

    export

    Parameters

    • deepArray: any[]
    • iteratee: (item: any, cord: number[], index: number) => any
        • (item: any, cord: number[], index: number): any
        • Parameters

          • item: any
          • cord: number[]
          • index: number

          Returns any

    • pos: number[] = []
    • index: any = ...

    Returns any

isNullOrEmpty

  • isNullOrEmpty(arr: any[] | undefined | null): boolean
  • Check if an array contains any elements. null/undefined are considered empty.

    export

    Parameters

    • arr: any[] | undefined | null

    Returns boolean

pick

  • pick(array: any[], ...indices: any[]): any
  • Pick a value from a deep array by its indices. e.g.: pick(arr, 1, 2, 3) = arr[1][2][3] if an array is supplied as the last parameter, it will be filled with arrays in each level e.g.: [rootArray, subArray, ..., parentArray]

    export

    Parameters

    • array: any[]
    • Rest ...indices: any[]

      target value indices in a deep array. e.g. the indice of value arr[i1][i2][i3] is [i1, i2, i3] the last one can be an empty array to hold parents in each level

    Returns any

swap

  • swap(arr: any[], pos1: number | number[], pos2: number | number[]): void
  • Swap value of array's two positions

    export

    Parameters

    • arr: any[]
    • pos1: number | number[]
    • pos2: number | number[]

    Returns void

    arr

unflatten

  • unflatten<T>(arr: T[], keyProperty: string, linkProperty: string, childrenProp?: string): T[]
  • Experiment feature...

    export

    Type parameters

    • T

    Parameters

    • arr: T[]
    • keyProperty: string
    • linkProperty: string
    • childrenProp: string = '__children__'

    Returns T[]

Generated using TypeDoc