Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package codecollection.snippets.strings

fun isPalindrome(input: String): Boolean {
val filtered = input.filter { it.isLetterOrDigit() }.lowercase()
return filtered == filtered.reversed()
}
1 change: 1 addition & 0 deletions src/main/kotlin/codecollection/snippets/strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ Each snippet is implemented as an extension function or utility method, and test
|--------------------------------------------------|---------------------------------------|
| [`ConvertToCamelCase.kt`](ConvertToCamelCase.kt) | Converts strings to camelCase format |
| [`ReplaceMultipleSpaces.kt`](ReplaceMultipleSpaces.kt) | Replaces consecutive whitespace with a single space |
| [`IsPalindrome.kt`](IsPalindrome.kt) | Checks whether the string is a palindrome or not|
| _More coming soon..._ | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package codecollection.snippets.strings

import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class IsPalindromeTest {

@Test
fun testPalindromeWithSimpleWord() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the rest of the codebase, please rename test functions using backticks and natural language descriptions (e.g., fun recognizes simple word palindrome()). Here and in functions below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the feedback! 🙌
I’ll update the test function names to use backticks and natural language descriptions as suggested (e.g., fun recognizes simple word palindrome()), to keep it consistent with the rest of the codebase. Appreciate you pointing that out — will make the changes shortly!

assertTrue(isPalindrome("madam"))
}

@Test
fun testPalindromeWithPunctuation() {
assertTrue(isPalindrome("A man, a plan, a canal: Panama"))
}

@Test
fun testNonPalindrome() {
assertFalse(isPalindrome("hello"))
}
}