Skip to content

Documentation / @andrew_l/toolkit / negate

Function: negate() ​

negate<F>(func): F

Creates a function that negates the result of the predicate function.

Type Parameters ​

F ​

F extends (...args) => boolean

The type of the function to negate.

Parameters ​

func ​

F

The function to negate.

Returns ​

F

The new negated function, which negates the boolean result of func.

Example ​

ts
const array = [1, 2, 3, 4, 5, 6];
const isEven = (n: number) => n % 2 === 0;
const result = array.filter(negate(isEven));
// result will be [1, 3, 5]