Function firstIndexOfLastGroup

  • Category

    Returns the first index of the last 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

    • array: ArrayLike<T>

      The array to search

    • value: T

      The value to search for

    Returns number

    The first index of the last group of a given value

    Example

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

    firstIndexOfLastGroup(array, 'c'); // 4

    See

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

    Array