object Scala99Problem01{
def lastElement[A](ls: List[A]):A = {
def lastElementAux[A](ls: List[A]): Option[A] = ls match{
case Nil => None
case x :: Nil => Some(x)
case x :: xs =>
There are several ways to accomplish this. Next code snippet shows how to compute min and max using reduceLeft.
val ls = List(1,2,3,4,5)
ls.reduceLeft(_ min _) // is equivalent to
Following is a simple solution to the LeetCode's Reverse Words in a String problem.
def reverseWords(s: String) =
s.split (" ")
.reverse
.mkString(" ")
Lets execute it in the
This is an interesting article by @DanCast that attempts to answer a long-standing question: What does "Senior" entail in the role of “Senior” Software Engineer? A must read for any aspiring