nattyddubbs has a nice implementation of your function without returns, but I can add a bit about why intellij is warning you about them.
Basically return
works slightly differently in scala to what you might expect - the guys at jetbrains know that and have added a warning to make sure you really want a return there.
The problem is it returns the caller to the method in which the return appears... not the function. The best place to see this is in anonymous functions, for example imagine you have a function to sum a list
scala> def summer(as: List[Int]): Int = as.foldRight(0)((i,j) => i + j)
scala> summer(List(33, 42, 99))
res2: Int = 174
Cool. What happens if you use return?
scala> def summer(as: List[Int]): Int = as.foldRight(0)((i,j) => return i + j)
scala> summer(List(33, 42, 99))
res3: Int = 99
The meaning of the function has completely changed ... and you might not have expected it
OK you'd probably never write a return in a simple function like this, but you could easily do it in a more complex lambda and end up with results you don't expect
Rob Norris wrote a good blog post about return in scala here which is really worth reading