小编asi*_*sif的帖子

Convert sphere function to tail recursive function

I have implemented Sphere function (takes a List of elements, squares every element and returns sum) in Scala. I want to convert this function to tail recursive. My code is here

def Sphere(list: List[Double]): Double = {
  val power = list.map(math.pow(_, 2))
  power.reduce(_+_)
}
Run Code Online (Sandbox Code Playgroud)

scala tail-recursion

1
推荐指数
1
解决办法
67
查看次数

标签 统计

scala ×1

tail-recursion ×1