UNPKG

415 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.product = product;
7
8/** @param {number} i
9 * @param {number} n
10 * @returns {number} product of i to n
11 */
12function product(i, n) {
13 if (n < i) {
14 return 1;
15 }
16
17 if (n === i) {
18 return n;
19 }
20
21 var half = n + i >> 1; // divide (n + i) by 2 and truncate to integer
22
23 return product(i, half) * product(half + 1, n);
24}
\No newline at end of file