Basis Technologies interview question

Scala function to find the last element of a list using tail recursion

Interview Answer

Anonymous

12 Jan 2020

def last(l: List[Int]): Int = if (l.tail == Nil) l.head else method(l.tail)