Function filterAB

Returns two separate arrays of everything that filter returns true, and everything it returns false on. The in-built Array.filter() in constrast only returns things that filter returns true for.

const [ matching, nonMatching ] = filterAB(data, v => v.enabled);
// `matching` is a list of items from `data` where .enabled is true
// `nonMatching` is a list of items from `data` where .enabled is false
  • Type Parameters

    • V

    Parameters

    • data: readonly V[]

      Array of data to filter

    • filter: ((a: V) => boolean)

      Function which returns true to add items to the A list, or false for items to add to the B list

        • (a): boolean
        • Parameters

          Returns boolean

    Returns [a: V[], b: V[]]

    Array of two elements. The first is items that match filter, the second is items that do not.