Skip to content
24 linesCodeBlameRaw
1// Small helpers for numbers.
2/** Returns the sum of a and b. */
3function add(a, b) {
4 return a + b;
5}
6
7/** Returns the product of a and b. */
8function multiply(a, b) {
9 return a * b;
10}
11
12/** Returns base raised to the whole-number exponent; throws a RangeError if exponent is negative. */
13function power(base, exponent) {
14 if (exponent < 0) {
15 throw new RangeError("exponent must not be negative");
16 }
17 let result = 1;
18 for (let i = 0; i < exponent; i++) {
19 result *= base;
20 }
21 return result;
22}
23
24module.exports = { add, multiply, power };