Created
November 3, 2020 03:51
-
-
Save cuongld2/5a4a75c8d250059b606b5899c60ab927 to your computer and use it in GitHub Desktop.
sum recursive functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum(xs: List[Int]): Int = { | |
if( xs.isEmpty) | |
0 | |
else | |
xs.head + sum(xs.tail) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment