Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "index"

Index

Functions

deepClone

  • deepClone(array: any[]): any[]
  • Deep clones an array of instances of type T and returns a new array.

    example
    const original = [new Todo(), new Todo()];
    const result = [new Todo(), new Todo()];
    expect(deepClone(original)).to.eql(result);
    

    Parameters

    • array: any[]

      The array to deep clone

    Returns any[]

    A new deep clone of the array argument

    Note that all the instances being cloned must implement this type of constructor:

    constructor(obj: any) {
    Object.assign(this, obj);
    

pop

  • pop<T>(array: T[]): T[]
  • Removes the last element

    example
    const original = ["a", "b"];
    const result = ["a"];
    expect(remove(original, 1)).to.eql(result);
    

    Type parameters

    • T

    Parameters

    • array: T[]

    Returns T[]

    A new array with the last element removed

post

  • post<T>(original: T[], elements: T[]): T[]
  • Concanates the elements in the array argument onto the original array.

    example
    const original = ["a", "b"];
    const result = ["a", "b", "c", "d"];
    expect(concat(original, ["c", "d"])).to.eql(result);
    

    Type parameters

    • T

    Parameters

    • original: T[]

      The original array

    • elements: T[]

      The array to concatenate

    Returns T[]

    A new array with elementN array concatenated onto the original array.

pre

  • pre<T>(original: T[], elements: T[]): T[]
  • Places the elements in the array argument first in the original array and returns a new array.

    example
    const original = ["a", "b"];
    const result = ["a", "b", "c", "d"];
    expect(concat(original, ["c", "d"])).to.eql(result);
    

    Type parameters

    • T

    Parameters

    • original: T[]

      The original array

    • elements: T[]

      The array to concatenate

    Returns T[]

    A new array with elementN array inserted at the beginning of the original array.

pull

  • pull<T>(array: T[], ...elementN: T[]): T[]
  • Adds one or more elements to the beginning of the array.

    example
    const original = ["a", "b"];
    const result = ["c", "d", "a", "b"];
    expect(pull(original, "c", "d")).to.eql(result);
    

    Type parameters

    • T

    Parameters

    • array: T[]

      The array to add the elements to

    • Rest ...elementN: T[]

      The element(s) to add to the beginning of the array

    Returns T[]

    The new array with the elements added to the beginning of it.

push

  • push<T>(original: T[], ...elementN: T[]): T[]
  • Pushes the elements onto the end of the array and returns a new array.

    example
    const original = ['a', 'b'];
    const result = ['a', 'b', 'c', 'd'];
    expect(push(original, 'c', 'd')).to.eql(result);
    

    Type parameters

    • T

    Parameters

    • original: T[]

      The original array

    • Rest ...elementN: T[]

      The arguments to be inserted

    Returns T[]

    The result array

remove

  • remove<T>(array: T[], index: number): T[]
  • Removes an element from an array by its index in the array.

    example

    const original = ['a', 'b']; const result = remove(original, 1); console.log(result); ['a']

    Type parameters

    • T

    Parameters

    • array: T[]
    • index: number

      The index of the item to remove

    Returns T[]

    The new array resulting from the removal of the index item

reverse

  • reverse<T>(array: T[]): T[]
  • Reverses an array and returns a new array.

    example
    const original = [20, 10];
    const result = [10, 20];
    expect(reverse(original)).to.eql(result);
    

    Type parameters

    • T

    Parameters

    • array: T[]

      The array to reverse

    Returns T[]

    A new array that is the reverse of the argument

sortNumbersAscending

  • sortNumbersAscending(array: number[]): number[]
  • Sorts the numbers of an array in ascending order and returns a new array.

    example
    const original = [20, 10];
    const result = [10, 20];
    expect(sortNumbersAscending(original)).to.eql(result);
    

    Parameters

    • array: number[]

      The array to sort

    Returns number[]

    A new array with the numbers sorted in ascending order

sortNumbersDescending

  • sortNumbersDescending(array: number[]): number[]
  • Sorts the numbers of an array in descending order and returns a new array.

    example
    const original = [10, 20];
    const result = [20, 10];
    expect(sortNumbersDescending(original)).to.eql(result);
    

    Parameters

    • array: number[]

      The array to sort

    Returns number[]

    A new array with the numbers sorted in descending order

sortStringsAscending

  • sortStringsAscending(array: string[]): string[]
  • Sorts the string elements of an array in ascending order.

    example
    let original = ["Beta", "Alpha"];
    let result = ["Alpha", "Beta"];
    expect(sortStringsAscending(original)).to.eql(result);
    

    Parameters

    • array: string[]

    Returns string[]

sortStringsDescending

  • sortStringsDescending(array: string[]): string[]
  • Sorts the string elements of an array in descending order.

    example
    let original = ["Alpha", "Beta"];
    let result = ["Beta", "Alpha"];
    expect(sortStringsDescending(original)).to.eql(result);
    

    Parameters

    • array: string[]

    Returns string[]

toArrayByObjectKey

  • toArrayByObjectKey<E>(entities: E[]): any
  • For each instance of type E in the array argument map the property values into arrays keyed by the name of the property in the instance of type E.

    example
    students:Student[] = [
    {id:1, name:'1', sex:'X', standard: 1, propName: 11, anotherSillyPropName:111,},
    {id:2, name:'2', sex:'Y', standard: 2, propName: 22, anotherSillyPropName:222,},
    {id:3, name:'3', sex:'Z', standard: 3, propName: 33, anotherSillyPropName:333,},
    ]
    
    console.log(toArrayByObjectKey(students))

    CREDIT: Implementation provided by Georg per this SO answer: https://stackoverflow.com/questions/55404204/attempting-to-understand-reduce-functions-for-object-mapping

    Type parameters

    • E

    Parameters

    • entities: E[]

      The array of entities

    Returns any

    A single object with all the property values on the entities mapped into arrays.

Generated using TypeDoc