Skip to content

Instantly share code, notes, and snippets.

@kell18
Created January 4, 2017 21:11
Show Gist options
  • Select an option

  • Save kell18/0e8c62d15597d14d272dac5b3d4197ee to your computer and use it in GitHub Desktop.

Select an option

Save kell18/0e8c62d15597d14d272dac5b3d4197ee to your computer and use it in GitHub Desktop.
object PalindromeChecker {
def isPalindrome(words: Array[String]) {
words.foreach(w => println(isPalindrome1(w)))
}
def isPalindrome(word: String): Boolean = {
var b = 0
var e = word.length-1
while (b < e) {
if (word.charAt(b) != word.charAt(e)) return false
b += 1
e -= 1
}
return true
}
def isPalindrome1(word: String) = word == word.reverse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment