Files
30-seconds-of-code/snippets/complement.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

513 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Logical complement function,logic flower-portrait-10 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 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