Skip to content
Advertisement

Factorial function using lambda

I am trying to implement the function below into one line of lambda code.

JavaScript

I have constructed a lambda statement, but I keep getting syntax error:

JavaScript

Advertisement

Answer

First of all, you can’t refer to a global name z when there is a local variable (the parameter) by the same name.

Thus, we will declare a lambda statement called func and use the ternary operator in the good way.

JavaScript

Output

JavaScript
Advertisement