To handle variadic functions:
Gathering arguments in an array named "arguments" and passing them to the function.
function not(myFunction){
if (typeof myFunction != "function"){return !myFunction }
return function (...args) {
return !myFunction.apply(null,args)
}
}
In summary:
const not = f => (...a) => !f.apply(null,a)
Additionally, to ensure it works for all values - checking if a function is being passed. This allows using it like this not(bigger(1,2))
:
function not(anything){
if (typeof anything != "function"){return !anything }
return function (...args) {
return !anything.apply(null,args)
}
}
var variable = true
console.log(not(bigger(6))) >>> true
console.log(not(variable))) >>> false
console.log(not(false))) >>> true
In summary:
const not = f => typeof f != "function" ? !f : (...a) => !f.apply(null,a)