Challenge: Sum of Lists

Test yourself and implement what you have learned so far in this challenge.

Problem Statement

In this challenge, you need to create a recursive function sum which returns the total sum of the integers in a List.

The provided skeleton code uses match and you are required to use the skeleton code. However, there is an alternate solution to this problem which we will discuss in the solution review.

Input

The input of the function is a List of integers numberList.

Output

The output will be the sum of all the integer in numberList.

Sample Input

List(1,2,3,4,5)

Sample Output

15

Test Yourself

Write your code in the given area. Try the exercise by yourself first, but if you get stuck, the solution has been provided. Good luck!

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy