mathjs
Version:
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif
18 lines (16 loc) • 332 B
JavaScript
/** @param {integer} i
* @param {integer} n
* @returns : product of i to n
*/
function product (i, n) {
let half
if (n < i) {
return 1
}
if (n === i) {
return n
}
half = (n + i) >> 1 // divide (n + i) by 2 and truncate to integer
return product(i, half) * product(half + 1, n)
}
module.exports = product