I am developing translate function in Scala. It consists to insert the "av" character, just before a vowel-like 'a' , 'e' , 'i', 'o' or 'u'.
Note that text string has length restrictions. It should not has a length of more than 225 characters and if it's empty, it should return an empty string:
In another world:
if
text = "abdcrfehilmoyr"
the result should be : "avabdcrfehavilmavoyr"
So, I developed this function :
def translate(text: String): String = {
var voyelle = Array('a', 'e', 'i', 'o', 'u')
for (w <- (0,text.length())){
if ((text.contains(voyelle[w]) == true)) {
text.patch(w, "av", 0)
}
}
}
Is there a way, to use instead functional programming like map, flat map functions to simplify the code ?
for(w <- (0,text.length()))doesn't work like this.flatMapthat is all you asked, hope you can find the answer.