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
Higher-order functions take other functions as arguments and/or return other functions as a result. These powerful abstractions allow us…
Rust is a compiled, multi-paradigm, low-level, statically-typed, general-purpose programming language emphasizing performance, type safety, and concurrency. It was originally…
Writing code can be as simple as importing the required libraries, declaring our variables, functions, and classes as required,…
Data science has its roots in statistics, computer science, and data analysis in the 1960s. It has since evolved…

Request Full Resume