An interview question about valueOf's JavaScript

implement a sum method to make it behave as follows

sum(2,3).valueOf()    //5
    
sum(2,3,4).valueOf()        //9
    
sum(2,3)(4).valueOf()        //9
    
sum(2,3,4)(2)(3,4).valueOf()         //18

the previous parts sum () , sum () () are easy to say. But how do you rewrite valueOf to print the sum of the data returned by the previous execution method?

Jul.15,2021

The results of

sum () can continue to use the () operator, indicating that sum () returns a function (function / function expression / arrow function collectively); in addition, the return value also has a valueOf () method, so you can put a box

first.
 
< hr >
< hr >
< hr >
! [quote text] [1]
Menu