Class SequentialContainer<T>Abstract

Type Parameters

  • T

Hierarchy

Constructors

Accessors

  • get length(): number
  • Returns

    The size of the container.

    Example

    const container = new Vector([1, 2]);
    console.log(container.length); // 2

    Returns number

Methods

  • Description

    Iterate over all elements in the container.

    Example

    container.forEach((element, index) => console.log(element, index));
    

    Parameters

    • callback: ((element: T, index: number, container: Container<T>) => void)

      Callback function like Array.forEach.

        • (element: T, index: number, container: Container<T>): void
        • Parameters

          • element: T
          • index: number
          • container: Container<T>

          Returns void

    Returns void

  • Description

    Removes the element at the specified position.

    Returns

    The container length after erasing.

    Example

    container.eraseElementByPos(-1); // throw a RangeError
    

    Parameters

    • pos: number

      The element's position you want to remove.

    Returns number

  • Description

    Sets element by position.

    Example

    container.setElementByPos(-1, 1); // throw a RangeError
    

    Parameters

    • pos: number

      The position you want to change.

    • element: T

      The element's value you want to update.

    Returns void

  • Description

    Removes the elements of the specified value.

    Returns

    The size of container after erasing.

    Example

    container.eraseElementByValue(-1);
    

    Parameters

    • value: T

      The value you want to remove.

    Returns number

  • Description

    Insert several elements after the specified position.

    Returns

    The size of container after inserting.

    Example

    const container = new Vector([1, 2, 3]);
    container.insert(1, 4); // [1, 4, 2, 3]
    container.insert(1, 5, 3); // [1, 5, 5, 5, 4, 2, 3]

    Parameters

    • pos: number

      The position you want to insert.

    • element: T

      The element you want to insert.

    • Optional num: number

      The number of elements you want to insert (default 1).

    Returns number

  • Description

    Removes the duplication of elements in the container.

    Returns

    The size of container after inserting.

    Example

    const container = new Vector([1, 1, 3, 2, 2, 5, 5, 2]);
    container.unique(); // [1, 3, 2, 5, 2]

    Returns number

  • Description

    Sort the container.

    Returns

    The container's self.

    Example

    const container = new Vector([3, 1, 10]);
    container.sort(); // [1, 10, 3]
    container.sort((x, y) => x - y); // [1, 3, 10]

    Parameters

    • Optional cmp: ((x: T, y: T) => number)

      Comparison function to sort.

        • (x: T, y: T): number
        • Parameters

          • x: T
          • y: T

          Returns number

    Returns SequentialContainer<T>

Generated using TypeDoc