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)