FP — recursion in Scala and Javascript syntax

Scala

def fact(i: Int, accumulator: Int): Long = {
if (i <= 1) accumulator else fact(i — 1, i * accumulator) }
}

(0 to 5) foreach ( i => println(fact(i,1)) )

Javascript

function fact(i, acc){

return (i<=1) ? acc : fact(i-1, i*acc);

}

[0,1,2,3,4,5].forEach(function(num){ console.log(fact(num,1);});

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.