@jiminp/tooltool
    Preparing search index...

    Function partition

    • Partitions an array into two arrays based on a predicate.

      Type Parameters

      • T

        Element type.

      • U

      Parameters

      • arr: T[]

        Array to partition.

      • predicate: (value: T, index: number, array: T[]) => value is U

        Predicate function.

      Returns [falsey: Exclude<T, U>[], truthy: U[]]

      [falsey, truthy] tuple.

      partition([1, 2, 3, 4], (n) => n % 2 === 0); // [[1, 3], [2, 4]]
      
    • Partitions an array into two arrays based on a predicate.

      Type Parameters

      • T

        Element type.

      Parameters

      • arr: T[]

        Array to partition.

      • predicate: (value: T, index: number, array: T[]) => boolean

        Predicate function.

      Returns [falsey: T[], truthy: T[]]

      [falsey, truthy] tuple.

      partition([1, 2, 3, 4], (n) => n % 2 === 0); // [[1, 3], [2, 4]]