Function lastIndexOfFirstGroup

  • Returns the last index of the first continuous group of a given value. Strict equality (===) is used to compare elements.

    Time complexity: O(n)

    Space complexity: O(1)

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      The iterable to search

    • value: T

      The value to search for

    Returns number

    The last index of the first group of a given value

    const iterable = ['a', 'a', 'b', 'b', 'c', 'c'];

    lastIndexOfFirstGroup(iterable, 'a'); // 1

    firstIndexOfLastGroup to do the same thing but find the first index of the last group

    Iterable