DEV Community

Matt Smithies
Matt Smithies

Posted on

Recursion of lists of numbers

Implement a function sum, which will be executed multiple times with n integers. There are 3 levels of difficulty:

Easy

For example:

sum(2,3)() 
result: 5

sum(9,3)() 
result: 12

Medium

For example:

sum(2,3)(1,3)()
result: 9

sum(9,3)(2,2)(1,1,2,1)(9)() 
result: 30

Hard

[Hint] This final challenge, think of solutions that are off the beaten path.

Create a generic case where sum will seemingly have many calls and the parameters for a given execution will always be 1 or more integers.

For example:

sum(2,3)
result: 5

sum(2,3)(1)(2,2)
result: 10

sum(2,3)(1,3)(9,10)
result: 27

sum(9,3)(2,2)(1,1,2,1)(9) 
result: 30

Good luck and have fun!

Matt.

Top comments (0)