Question: B (10 points) Tail Recursive cubeIt Now, write a tail recursive version of the cubeIt function above, called cubeItTail. We have setup a helper function
B (10 points) Tail Recursive cubeIt Now, write a tail recursive version of the cubeIt function above, called cubeItTail. We have setup a helper function with an accumulator argument for you, to help you out. Do not remove the @tailrec annotation. It is part of the autograder: you can learn more about it's meaning here - https://www.scala-exercises.org/scala_tutorial/tail_recursion import scala.annotation.tailrec atailreo def cubeItHelper(n: Int, acc: Int): Int ={ Implement cubeIt as a tail recu II YOUR CODE HERE ??? 3 This This is the main function that the users will use. It should call the helper with the correct initial value of acc argument. Just replace the ??? with the correct initial value for the acc argument. def cubeItTail( n: Int ): Int ={ cubeItHelper (n, YOUR CODE HERE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
