UNPKG

332 BJavaScriptView Raw
1/** @param {integer} i
2 * @param {integer} n
3 * @returns : product of i to n
4 */
5function product (i, n) {
6 let half
7 if (n < i) {
8 return 1
9 }
10 if (n === i) {
11 return n
12 }
13 half = (n + i) >> 1 // divide (n + i) by 2 and truncate to integer
14 return product(i, half) * product(half + 1, n)
15}
16
17module.exports = product