I am solving trivial problems to learn Scala. Here is what I have come up with
def isUnique(str: String): Boolean = {
if (str.length > 128) return false
val uniqueChars = new Array[Boolean](128)
!(str.map(c => addChar(c, uniqueChars)).find(identity).isDefined)
}
def addChar(ch: Char, uniqueChars: Array[Boolean]): Boolean = {
if (uniqueChars(ch)) return true else {
uniqueChars(ch) = true;
return false
}
Is that it?
Please note that I don't care about the logic or optimization at this point. I only need to learn the Scala way of doing it.
[Edit] Let's assume we don't want to use the string distinct method. I only need to verify the functional style of Scala.