Interface representing a generic List ADT.

interface List<T> {
    size: number;
    [iterator](): Iterator<T, any, any>;
    append(item: T): void;
    clear(): void;
    contains(item: T): boolean;
    forEach(callback: ((item: T, index: number) => void)): void;
    get(index: number): undefined | T;
    indexOf(item: T): number;
    insert(index: number, item: T): void;
    isEmpty(): boolean;
    remove(item: T): boolean;
    removeAt(index: number): undefined | T;
    toArray(): T[];
}

Type Parameters

  • T

Hierarchy (view full)

Implemented by

Properties

size: number

Gets the number of elements in the collection.

Methods

  • Return an iterator for List.

    Returns Iterator<T, any, any>

  • Adds an element to the end of the list.

    Parameters

    • item: T

      The element to add.

    Returns void

  • Returns true if the list contains the specified element.

    Parameters

    • item: T

      The element to check for.

    Returns boolean

    True if the element is in the list, otherwise false.

  • Iterates over the list and executes the provided function for each element.

    Parameters

    • callback: ((item: T, index: number) => void)

      The function to execute for each element.

        • (item, index): void
        • Parameters

          • item: T
          • index: number

          Returns void

    Returns void

  • Returns the element at a specific position.

    Parameters

    • index: number

      The position of the element to return.

    Returns undefined | T

    The element at the specified position, or undefined if the index is out of bounds.

  • Returns the index of the first occurrence of an element, or -1 if not found.

    Parameters

    • item: T

      The element to search for.

    Returns number

    The index of the element, or -1 if not found.

  • Inserts an element at a specific position in the list.

    Parameters

    • index: number

      The position to insert the element.

    • item: T

      The element to insert.

    Returns void

  • Removes the first occurrence of an element from the list.

    Parameters

    • item: T

      The element to remove.

    Returns boolean

    True if the element was removed, otherwise false.

  • Removes and returns the element at a specific position.

    Parameters

    • index: number

      The position of the element to remove.

    Returns undefined | T

    The removed element, or undefined if the index is out of bounds.

  • Returns an array representation of the list.

    Returns T[]

    An array containing all the elements in the list.