I am new to Scala and would like to apply a (let math.log
) function to all elements of the [Double] array. Th foreach
doesn't work. What's the best way to do this?
Here is my code:
def func(arr: Array[Double]): Double = {
arr.map(a => log(a)).sum
}
source
to share