Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 412 Bytes

complement.md

File metadata and controls

19 lines (15 loc) · 412 Bytes
title tags
complement
function,logic,beginner

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