I need to guarantee a string only contains allowed symbols. Now I do it this way:
def isCorrect(s: String, allowedChars: String): Boolean = {
s.distinct.foreach(c => {
if (!allowedChars.contains(c))
return false
})
true
}
Needless to say this does not look too pretty. Is there a better, more functional way to do this?
I dont know if it is the most functional way to do it, but you can do this:
the distinct isnt really necessary.