factorial program in javascript
function factorial(n) {
if (n < 0) return;
if (n < 2) return 1;
return n * factorial(n - 1);
}function fact(N){
if(N <= 1){
return "1";
}
else
{
return N * fact(N-1);
}
}
fact(5);const factorial = n => n <= 1 ? 1 : n * factorial(n - 1);
// Examples
factorial(2); // 2
factorial(3); // 6function factorialize(num) {
if (num === 0 || num === 1)
return 1;
for (var i = num - 1; i >= 1; i--) {
num *= i;
}
return num;
}
factorialize(5);function fact(N){
if(N <= 1){
return "1";
}
else
{
return N * fact(N-1);
}
}
fact(5);
Also in JavaScript:
- statusbar reactnati
- random string js
- how to use axios in vue
- riverSizes javascript
- check a string for unique characters javascript
- learn json
- event exit fullscreen
- next js _app getinitialprops
- Postfix increment
- How to change htm h1 from nodejs
- how to use online mysql database with node js
- how react work
- difference between key and code in javascript
- load +main.js with system.import
- port 3000 is already in use nodemon app crashed
- int val javascript
- node express server static files
- how to change a string to number in javascript
- javascript backticks and if statements
- read xlsx file in angular 5
- vuejs show {{}} on loading
- how to bind a json output result to any new model
- javascript remove last charter stings
- how to find index of max number in js