You are viewing a single comment's thread. Return to all comments →
Using for loop:
const factorial = (n) => { let fact = 1; for( let i = n; i>0; i--){ fact = fact*i } return fact; }
Using recursion:
const factorial = (n) => { if (n == 1) return 1; return n * factorial(n-1); }
OR
const factorial = (n) => n == 1 ? 1 : n * factorial(n-1);
Seems like cookies are disabled on this browser, please enable them to open this website
Day 1: Functions
You are viewing a single comment's thread. Return to all comments →
Using for loop:
Using recursion:
OR