def f(c: String) = {
val array = ("google.com|yahoo.com|gmail.com|mail.com").split("\\|")
for (i <- array) {
if (c.contains(i)) {
println("comparing " + c + " with " + i)
i
}
}
"N/A"
}
My intention for the above function is that, it will return N/A if c does not contain any of the elements of the array. And, if it does, it will return the element in the array. So if c="www.google.com/1234" , ideally the function would return google.com and if c="bloomberg.com/example", the function will return N/A.
But when I do println(f("www.google.com/1234")) I get N/A.
Can anyone tell me what am I doing wrong.
for()statement goes through the entirearray. After it's finished the program moves to the next line:"N/A"Since that's the last line of the method, that's what the method returns, no matter what happens in thefor()..