Skip to content

Instantly share code, notes, and snippets.

@jtrupiano
Created April 20, 2009 23:10
Show Gist options
  • Save jtrupiano/98834 to your computer and use it in GitHub Desktop.
Save jtrupiano/98834 to your computer and use it in GitHub Desktop.
def nth(n:Int, lst: List[Int]): Int = {
if (n == 0) {
return lst.head
}
lst match {
case head :: tail => nth(n - 1, tail)
case Nil => throw new NoSuchElementException
}
}
println(nth(2, List(1, 1, 2, 3, 5, 8)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment