stack

Home > @infiniteobjects/core-library-web > Functions > negate

Functions.negate() method

Creates a function that negates the result of the predicate func. The func predicate is invoked with the this binding and arguments of the created function.

Signature:

static negate<T extends any[]>(func: (...args: T) => any): (...args: T) => boolean;

Parameters

Parameter Type Description
func (…args: T) => any  

Returns:

(…args: T) => boolean

Example

function isEven(n): boolean {
  return n % 2 == 0;
}

const arr = [1, 2, 3, 4, 5, 6]
arr.filter(Functions.negate(isEven))
// => [1, 3, 5]