Files
30-seconds-of-code/snippets/js/s/logical-complement.md
Angelos Chalaris 9d032ce05e Rename js snippets
2023-05-19 20:23:47 +03:00

514 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Logical complement snippet javascript
function
logic
flower-portrait-10 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 calling fn with any supplied args.
const complement = fn => (...args) => !fn(...args);
const isEven = num => num % 2 === 0;
const isOdd = complement(isEven);
isOdd(2); // false
isOdd(3); // true