How do I compare these two string :
val a = \"fit bit versa\"
val b = \"fitbit\"
another example
val a = \"go pro hero 6\"
Something like this I guess (your requirements are incomplete, so I interpreted them to "match exactly the beginning portion of the given string, ending with whitespace or end of line, except maybe spaces).
@tailrec
def matchWords(input: Seq[Char], words: Seq[Char]): Boolean = (input, words) match {
case (Seq(), Seq() | Seq(' ', _*)) => true
case (Seq(), _) => false
case (Seq(a, tail@_*), Seq(b, rest@_*)) if a == b => matchWords(tail, rest)
case (_, Seq(' ', rest@_*)) => matchWords(input, rest)
case _ => false
}