complement
Returns a function that is the logical complement of the given function, fn
.
Use the logical not (!
) operator on the result of calling fn
with any supplied args
.
typescript
type Func<T> = (...args: T[]) => any;
const complement =
(fn: Func<any>) =>
(...args: any[]) =>
!fn(...args);
typescript
const isEven = (num: number) => num % 2 === 0;
const isOdd = complement(isEven);
isOdd(2); // false
isOdd(3); // true