tracks/kotlin/exercises/anagram/.meta/src/reference/kotlin/Anagram.kt in trackler-2.2.1.52 vs tracks/kotlin/exercises/anagram/.meta/src/reference/kotlin/Anagram.kt in trackler-2.2.1.53
- old
+ new
@@ -1,8 +1,11 @@
-class Anagram(val word: String) {
+class Anagram(private val word: String) {
+
fun match(anagrams: Collection<String>) =
- anagrams.filter({ doesMatch(it) }).filterNot({ it.equals(word, ignoreCase = true) })
+ anagrams.filter { containSameChars(it.toLowerCase()) }
+ .filterNot { it.equals(word, ignoreCase = true) }
+ .toSet()
- private fun doesMatch(anagram: String) =
- anagram.toLowerCase().toCharArray().sorted() == word.toLowerCase().toCharArray().sorted()
+ private fun containSameChars(candidate: String) =
+ candidate.toLowerCase().toCharArray().sorted() == word.toLowerCase().toCharArray().sorted()
}