Recursive Max in Scala

Determining the maximum value in a collection via a recursive Scala function.
def recursiveMax(xs: List[Int]): Int = 
    def compareMax(x: Int, y: Int): Int = 
        if (x > y) x
        else y
    if (xs.isEmpty) 0
    else compareMax(xs.head, recursiveMax(xs.tail))

recursiveMax(List(2, 6, 1, 6, 8, 10, 11, 0, 11, 20, 20))

// res0: Int = 20
Scala
We live in an era where reliable data has become an invaluable asset. We’re constantly bombarded with information from…
Data science has its roots in statistics, computer science, and data analysis in the 1960s. It has since evolved…
Functional programming is a powerful and elegant approach to tackling complex problems while creating maintainable code. Even though it…
A Big Data file format is designed to store high volumes of variable data optimally. This can be achieved…

Request Full Resume