I have two different functions:
Function called 'first' which takes 1 argument
Another function called 'second' that takes 2 arguments
Next, there is a third function that accepts a function and a value as its parameters.
I am struggling to understand how to make the third function capable of determining whether it is receiving one argument or two depending on the function passed in as the second argument???
**In the following example, when 'third' is invoked, it should output 2 for both calls at the end of the code.
let val = 12;
let val2 = 14
let toC = 14;
// If val === 12, returns 2 (takes only 1 argument)
const first = num => num === 12 ?2 :0;
// If val === toC, returns 2 (takes 2 arguments)
const second = (num, check) => num === check ?2 :0;
// Third function accepting a function and value as arguments
const third = (func, num) => {
let temp = func(num);
return temp;
}
// this works as expected
console.log(third(first, val);
// this does not work correctly
console.log(third(second, (val2, toC));