forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorial.js
More file actions
34 lines (29 loc) · 669 Bytes
/
Copy pathFactorial.js
File metadata and controls
34 lines (29 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Calculates the factorial of a given number for integer values greater than 0.
*
* @function Phaser.Math.Factorial
* @since 3.0.0
*
* @param {number} value - A positive integer to calculate the factorial of.
*
* @return {number} The factorial of the given number.
*/
var Factorial = function (value)
{
if (value === 0)
{
return 1;
}
var res = value;
while (--value)
{
res *= value;
}
return res;
};
module.exports = Factorial;