Where is the tail recursion?

Report a typo

Here is two implemented function that reverse the List[Int]:

def reverse1(remaining: List[Int]): List[Int] =
  remaining match
    case Nil          => Nil
    case head :: tail => reverse1(tail) :+ head

def reverse2(reversed: List[Int], remaining: List[Int]): List[Int] =
  remaining match
    case Nil          => reversed
    case head :: tail => reverse2(head :: reversed, tail)

Which function is tail-recursive?

Select one option from the list
___

Create a free account to access the full topic