Recursion and Tail Recursion in Scala : An easy step by step guide.
Briefly

A simple base case (or cases) : -Here, we define a terminating case which does not require recursion to produce a final answer . In the factorial(x) example ,we can define the base case as factorial(x) = 1 , if x=0 or x=1
Below is the implement of the factorial function in Scala. def factorials(x : Int) : Int = { //to ensure that x is non-negative require(x >= 0, "x must be greater than or equal to zero!") //base case if x <= 1 then 1 else //recursive step x * factorials(x-1)}
Read at Medium
[
|
]