A smart friend of yours wrote the following code to filter peaceWords to only [I, love, peace] using filter and regex. The smartest people sometimes get stuck with trivial bugs for hours. Please fix the code for your friend.
Advanced lambda expressions
Trivial bug
Report a typo
Write a program in Kotlin
class Solution {
private val peaceWords = arrayOf("I","&&n",3,"love",1, "peace", "&&n")
private val pattern = Regex("\\d+")
val filteredPeaceWords = peaceWords.filter {
if (pattern.matches(it.toString())) {
return@filter true
}
it.toString() == "&&n"
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.