• Segregate the elements of the source array into two distinct arrays the first array holding the values for which the predicate returned true and the second array holding the values for which the predicate returned false.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to segregate

    • paritioner: ((item, index) => any)

      Partion function that puts the item in the right or left bucket depenbding on if it returns a falsish values

        • (item, index): any
        • Parameters

          • item: T
          • index: number

          Returns any

    • Optional predicate: ((item, index) => any)

      Predicate to filter the array

        • (item, index): any
        • Parameters

          • item: T
          • index: number

          Returns any

    Returns [T[], T[]]

    A tuple with two arrays the first array holding the values for which the predicate returned true and the second array holding the values for which the predicate returned false.

    Example

    // Segregate even and odd numbers
    const [ even, odd ] = partition([ 1, 2, 3, 4, 5 ], i => i % 2 == 0);
    console.log(even); // [ 2, 4 ]
    console.log(odd); // [ 1, 3, 5 ]