Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Order<T>

Class to do multiple columns object array ordering.

Type parameters

  • T

Hierarchy

  • Order

Index

Constructors

constructor

  • Create an order rule, used in orderBy, and can also be used to binary search from or binary insert into array with object type items

    Type parameters

    • T

    Parameters

    • Rest ...orders: OrderRule<T>[]

      Rest parameters of type key or OrderFunction which will return a key, or [key / OrderFunction, OrderDirection].

    Returns Order<T>

Methods

binaryFind

  • binaryFind(array: T[], item: T): undefined | T
  • Binary find the index from array the value at where equals to item. Returns -1 if not found.

    Parameters

    • array: T[]

      The array to lookup.

    • item: T

      The item to search.

    Returns undefined | T

binaryFindIndex

  • binaryFindIndex(array: T[], item: T): number
  • Binary find an index from array to insert item and keep current order. Returned value betweens 0 ~ array.length.

    Parameters

    • array: T[]

      The array to lookup.

    • item: T

      The item to compare.

    Returns number

binaryInsert

  • binaryInsert(array: T[], item: T): T[]
  • Binary insert an item into array and keeps current order. Note it uses splice to insert item, it's very slower since it reallocates memory frequently.

    Parameters

    • array: T[]

      The array to lookup.

    • item: T

      The item to insert.

    Returns T[]

compare

  • compare(a: T, b: T): 0 | 1 | -1
  • Compare two items. When order is 1: returns 0 if they are same; returns -1 if the first one less that the second one; else returns 1. When order is -1: returns 0 if they are same; returns 1 if the first one less that the second one; else returns -1.

    Parameters

    • a: T

      First item.

    • b: T

      Second item.

    Returns 0 | 1 | -1

sortArray

  • sortArray(array: T[]): void
  • Sort array inside by the order specified by current object.

    Parameters

    • array: T[]

      The array to sort.

    Returns void

Generated using TypeDoc