Trivial bug

Report a typo

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.

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"
}
}
___

Create a free account to access the full topic