How to write a javascript function that works for both the statements

How to write a javascript function that works for both the statements
0.0 0

#1

I have been asked in an interview to write a function that works for both the below mentioned statements.

sum(2,5)
sum(2)(5)


#2

Free Code Camp has the same challenge.

Have you written out your algorithm yet? If not, do that first and then test it out on paper to see if your algorithm would work for each test case above. Once you have an algorithm, try to convert it to JavaScript. If you get stuck, reply back to this same thread and post your code. Also, along with your code, explain what problems you are having.