Created
December 16, 2022 07:34
-
-
Save themexpride/d99d0ef48c1555f1080e42e5f40299d9 to your computer and use it in GitHub Desktop.
Update List of integers with their absolute values
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]):List[Int] = { | |
arr match { | |
case Nil => Nil | |
case h::t => { | |
if (h < 0) (-1 * h)::f(t) | |
else h::f(t) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment