Created
April 21, 2017 16:27
-
-
Save TRBaldim/345af36976c73136ee377c6a81250b1d to your computer and use it in GitHub Desktop.
Reverse a List in Scala
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
@tailrec | |
def reverseList[T](inputList: List[T], rList: List[T]): List[T] ={ | |
inputList match { | |
case Nil => rList | |
case h::t => reverseList(t, h::rList) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment