Skip to content

Instantly share code, notes, and snippets.

@InvisibleTech
Created September 6, 2015 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InvisibleTech/5e843afcfaf2006b4744 to your computer and use it in GitHub Desktop.
Save InvisibleTech/5e843afcfaf2006b4744 to your computer and use it in GitHub Desktop.
A recursive palindrome function. Needs to be case insensitive.
import scala.collection.immutable.StringOps._
@annotation.tailrec
def isPalindrome(strSeq : IndexedSeq[Char]) : Boolean = strSeq match {
case _ if strSeq.size < 2 => true
case _ if strSeq.take(1) == strSeq.takeRight(1) => isPalindrome(strSeq.slice(1, strSeq.size-1))
case _ => false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment