Skip to content

Instantly share code, notes, and snippets.

@themexpride
Created December 16, 2022 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themexpride/d99d0ef48c1555f1080e42e5f40299d9 to your computer and use it in GitHub Desktop.
Save themexpride/d99d0ef48c1555f1080e42e5f40299d9 to your computer and use it in GitHub Desktop.
Update List of integers with their absolute values
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