Function splitArray

  • Split an array when a predicate function determines an element is a predicate (similiar to String.prototype.split but for arrays)

    Returns

    the array of groups split as per the splitFn

    Example

    const groups = splitArray([1, 3, 5, 6, 7, 9, 11], (x) => x % 2 === 0) // [[1, 3, 5], [7, 9, 11]]
    

    Type Parameters

    • T

    Parameters

    • arr: T[]

      the array to split

    • splitFn: ((t) => boolean)

      a function over elements in the array that determines whether an element is a delimeter.

        • (t): boolean
        • Parameters

          • t: T

          Returns boolean

    Returns T[][]

Generated using TypeDoc