Created
March 20, 2017 10:52
-
-
Save gustavofranke/68b438cfa0d06be1449c290a36c34840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rev[A](str: List[A]): List[A] = str match { | |
case Nil => Nil | |
case x :: Nil => x :: Nil | |
case x :: y :: Nil => y :: x :: Nil | |
case x :: xs => xs.last +: rev(xs.init) :+ x | |
} | |
val gus = "Gustavo".toList //gus: List[Char] = List(G, u, s, t, a, v, o) | |
rev(gus) //res0: List[Char] = List(o, v, a, t, s, u, G) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment