maia-util
Version:
Utility math and music functions supporting various applications by Music Artificial Intelligence Algorithms, Inc.
27 lines (26 loc) • 510 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = factorial;
/**
* This function calculates the factorial of an input number, e.g.,
* x * (x - 1) * (x - 2) * ... * 2 * 1.
*
* @author Tom Collins
* @comment 30th March 2023
* @param {number} x - An integer.
* @return {number} The calculated factorial.
*
* @example
* factorial(4)
* →
* 24
*/
function factorial(x) {
if (x) {
return x * factorial(x - 1);
} else {
return x + 1;
}
}