-1

We have a function:

function f (a, b, c) {
function sum (a, b) {
return a + b;
}
}

Rewrite it as follows:

  1. If arguments a and b not transfered, they're equals by default 2 and 3.
  2. If argument c transfered and is a function, then it will run after the function sum called.
  3. Function f must return the result of a function argument c,if it exist,or result of a function sum.
Artem Poznyak
  • 23
  • 1
  • 4

1 Answers1

0

If I good understand your question this should be ok:

function f (a = 2, b = 3, c) {
    function sum(a, b) {
        return a + b;
    }
    let s =  sum(a,b);
    return c instanceof Function ? c() : s;
}

console.log(f());
console.log(f(7,8));
console.log(f(9,10, ()=>11));

We use here ternary operator, instanceof operator, and arrow function

Kamil Kiełczewski
  • 53,729
  • 20
  • 259
  • 241