Skip to content

Commit

Permalink
Create Palindrome.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvins committed Oct 24, 2024
1 parent ea3aa36 commit ef6dd33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4468,8 +4468,8 @@ In order to achieve greater coverage and encourage more people to contribute to
</a>
</td>
<td> <!-- Scala -->
<a href="./CONTRIBUTING.md">
<img align="center" height="25" src="./logos/github.svg" />
<a href="./src/scala/Palindrome.scala">
<img align="center" height="25" src="./logos/scala.svg" />
</a>
</td>
<td> <!-- Kotlin -->
Expand Down
15 changes: 15 additions & 0 deletions src/scala/Palindrome.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def isPalindrome(content: String): Boolean = {
val sanitizedContent: String = content.replaceAll("\\W", "").toLowerCase
sanitizedContent == sanitizedContent.reverse
}

object Main extends App {
val data: Seq[String] = Seq(
"",
"a",
"abba",
"No lemon, no melon",
"Was it a palindrome?"
)
data.foreach(x => println(s"'$x' is a palindrome? ${isPalindrome(x)}"))
}

0 comments on commit ef6dd33

Please sign in to comment.