Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Alternate Solution#

Sumit Rawal answered on May 23, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers


Alternate Solution#

0

The alternate solution to this challenge was using the if-else expression. The logic behind the code is pretty much the same as the match solution. The only difference is that the if-else solution takes a second parameter which is the length - 1 of list. In other words, if our list has 5 elements, we need to pass 4 to sum.

The first case is represented by if which is now checking if we have reached the start of the list (index < 0). The second case is represented by else which is adding the last element of the list (element at index 4) to the sum call sum(numberList, index-1). sum will now look at the list starting from the second to last index, i.e., 3. This will continue until we have reached the first element of the list.

Popularity 1/10 Helpfulness 1/10 Language scala
Source: Grepper
Link to this answer
Share Copy Link
Contributed on May 23 2023
Sumit Rawal
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.