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:
JavaScript
x
4
1
multiply(a,b) {
2
return a*b;
3
}
4
They expect me to do the math with:
JavaScript
1
2
1
multiply(a)(b)
2
Is it possible ?
Advertisement
Answer
Make a function that returns another function.
JavaScript
1
2
1
const multiply = a => b => a * b;
2
console.log(multiply(4)(3));