Options
All
  • Public
  • Public/Protected
  • All
Menu

External module primitive

Primitive module contain basic types used across algorithms and data structures

Index

Type aliases

Functions

Type aliases

ComparatorFn

ComparatorFn: function

Comparator function expect two parameters with the same type

returns

represent comparison operation, check below

  • parameters equal - return zero
  • a less then b - return less then zero
  • a great then b - return great then zero

Type declaration

    • (a: T, b: T): number
    • Parameters

      • a: T
      • b: T

      Returns number

Functions

genericComparator

  • genericComparator<T>(a: T, b: T): number
  • Generic comparator, working for primitive types like number, string, boolean

    import { genericComparator } from '@pencroff/ts-algorithms/dist/primitive/comparator';
    const res = genericComparator('A', 'B'); // -1

    Type parameters

    • T

      type of both input parameters

    Parameters

    • a: T
    • b: T

    Returns number

swap

  • swap<T>(collection: T[], idxA: number, idxB: number): void
  • Swap collection elements

    Type parameters

    • T

      type collection

    Parameters

    • collection: T[]

      collection of elements

    • idxA: number

      first element index

    • idxB: number

      second element index

    Returns void