Created
December 16, 2022 07:06
-
-
Save themexpride/b8c1a7ac35ad49cd6283523be2b23048 to your computer and use it in GitHub Desktop.
Sum of Odd Elements in Scala. Can add elements of a list that are odd and can be +/-
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 f(arr:List[Int]):Int = { | |
if (arr.isEmpty) 0 | |
else { | |
if (arr.head % 2 != 0) arr.head + f(arr.tail) | |
else f(arr.tail) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment