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
In today’s world, we’re constantly being bombarded with information from countless sources – news outlets, social media, blogs, etc….
We could spend our entire developer’s life using just the basic concepts of any programming language we choose to…
In our previous article, What Is Julia, and Why It Matters?, we discussed why Julia is so relevant today and…
In the last segment of this 5-piece Portfolio Project, we discussed what sentiment analysis is and the types of approaches for…

Request Full Resume