Factorial Number
function getFactorial($int)
{
$factorial = 1;
for ($i = $int; $i > 1; $i--)
{
$factorial *= $i;
}
echo "The factorial of " . $int . " is " . $factorial . '<br>';
}// METHOD ONE
const factorialNumber = num => {
let factorials = []
for(let i = 1; i <= num; i++) factorials.push(i)
return factorials.reduce((acc , curr) => acc * curr, 1)
}
// METHOD TWO
const factorialNumber = num => {
let factorial = 1, i = 1
while(i <= num){ factorial *= i; i++ }
return factorial
}
// METHOD THREE
function factorialNumber(num) {
if(num < 1) return 1
else return factorialNumber(num - 1) * num
}
Also in JavaScript:
- javascript double question mark
- find particular object from array in js
- how to uncheck a checkbox in jquery
- minify css package.json
- javascript jqgrid events afterShowForm
- reverse a linked list js
- disable paste space in textbox using javascript
- js revers string fucntion
- sorting array from highest to lowest javascript
- toggle class javascript and jquery
- find longest word in string javascript
- change abclground onload jquery
- facebook game files example
- fetch composition API in Vue3
- remove table line button html using javascript
- map with async
- agrgar atributo con id jquey
- Obtain smallest value from array of objects in Javascript
- mongodb replace document
- js reduce sum items of array
- play sound javascript
- how to compare elements in an array
- js object length
- how to split index.js to routes nodejs