Function splitArrayBy

  • Split an array when a predicate function returns true and return all the groups

    Returns

    the array of groups split as per the splitFn

    Example

    const runs = splitArrayBy([1, 2, 3, 10, 11, 12], (a, b) => b - a > 1)
    runs // [[1, 2, 3], [10, 11, 12]]

    Type Parameters

    • T

    Parameters

    • arr: T[]

      the array to split

    • splitFn: ((a, b) => boolean)

      a function over pairs of elements in the array that returns true when the elements should be in different groups

        • (a, b): boolean
        • Parameters

          • a: T
          • b: T

          Returns boolean

    Returns T[][]

Generated using TypeDoc