To account for variadic functions:
Collecting arguments in an array "arguments" and passing them on to the function.
function not(myFunction){
if (typeof myFunction != "function"){return !myFunction }
return function (...arguments) {
return !myFunction.apply(null,arguments)
}
}
in short:
const not = f => (...a) => !f.apply(null,a)
Also to make it work for all values - check if a function has been passed. which also allows to use it like so not(bigger(1,2)):
function not(anything){
if (typeof anything != "function"){return !anything }
return function (...arguments) {
return !anything.apply(null,arguments)
}
}
var variable = true
console.log(not(bigger(6))) >>> true
console.log(not(variable))) >>> false
console.log(not(false))) >>> true
in short:
const not = f => typeof f != "function" ? !f : (...a) => !f.apply(null,a)