Skip to content
Advertisement

Multiply (a)(b) function possible?

I have an oddball of a question from a code quiz. They expect me to write a function that multiplies (a) and (b) but instead of writing it like:

  multiply(a,b) {
    return a*b;
  }

They expect me to do the math with:

    multiply(a)(b)

Is it possible ?

Advertisement

Answer

Make a function that returns another function.

const multiply = a => b => a * b;
console.log(multiply(4)(3));
Advertisement