488 B
488 B
title, tags, firstSeen, lastUpdated
| title | tags | firstSeen | lastUpdated |
|---|---|---|---|
| complement | function,logic,beginner | 2020-05-13T11:28:33+03:00 | 2020-09-15T16:28:04+03:00 |
Returns a function that is the logical complement of the given function, fn.
- Use the logical not (
!) operator on the result of callingfnwith any suppliedargs.
const complement = fn => (...args) => !fn(...args);
const isEven = num => num % 2 === 0;
const isOdd = complement(isEven);
isOdd(2); // false
isOdd(3); // true