View updateListAbsVal.scala
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) | |
} | |
} | |
} |
View listLength.scala
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 1 + f(arr.tail) |
View sumOfOddElements.scala
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) | |
} | |
} |
View reverseList.scala
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 => f(t):::h::Nil | |
} | |
} |