I just started learning Scala and I am trying to solve a very simple exercise on HackerRank.
I get a number and a list as input and I want to print them N number of times.
This is the function I wrote:
def f(num:Int,arr:List[Int]):List[Int] = {
arr.foreach((element:Int) => print((s"$element" + "\n") * num))
}
Error:
Solution.scala:3: error: type mismatch;
found : Unit
required: List[Int]
arr.foreach((element:Int) => println((s"$element" + "\n") * num))
^
one error found
If I run the same thing in my scala (v2.13) console, I get the expected output