# All files / src/_utils partition.ts

100% Statements 6/6
100% Branches 2/2
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18

    7x

    1x
    4x
    4x

    4x

     /**
     * This implementation provides item and item's index to the predicate function and works only with arrays.
     * ramda's partition - doesn't provide indexes, but works with any iterable object
     * */
    export function partition<T>(
      predicate: (item: T, index: number) => boolean,
      list: readonly T[]
    ): [T[], T[]] {
      return list.reduce(
        ([resolved, rejected], item, index) => {
          predicate(item, index) ? resolved.push(item) : rejected.push(item)

          return [resolved, rejected]
        },
        [[] as T[], [] as T[]]
      )
    }