January 2020
Intermediate to advanced
470 pages
11h 13m
English
In the Logically negating a function section of Chapter 6, Producing Functions – Higher-Order Functions, we wrote a not() function that, given another function, would logically invert its result. We used that function to negate a check for negative balances; the sample code for this could be as follows:
const not = fn => (...args) => !fn(...args);const positiveBalance = not(isNegativeBalance);
In another section of that very same chapter, Turning operations into functions, I left you with the challenge of writing a unaryOp() function that would provide unary functions equivalent to common JavaScript operators. If you met that challenge, you should be able to write something like the following:
const logicalNot = unaryOp("!") ...