• Parameters

    • elements: any[]

      a list of elements of any type

    • comparison: Function

      a function which takes two "any" types (from elements) and returns true if they are similar, false otherwise.

    Returns number[][]

    a list of lists of indices referencing the input list, where each inner list is a cluster of similar element indices.

    Description

    Given a list of pre-sorted elements, create clusters where similarity is determined by a custom comparison function. Comparisons only need to happen to neighbors due to the array already being sorted. The type of elements in the list doesn't matter, so long as the comparison function can compare them.