Skip to content

Commit

Catch up with main

# Conflicts: # math.js # test.js

g1tbotcommitted Parents0940081f111277Browse files
2 files+16−10/2 viewed
+13−1
1717 return a / b;
1818 }
1919
20−module.exports = { add, multiply, divide };
20+/** Returns base raised to the whole-number exponent; throws a RangeError if exponent is negative. */
21+function power(base, exponent) {
22+ if (exponent < 0) {
23+ throw new RangeError("exponent must not be negative");
24+ }
25+ let result = 1;
26+ for (let i = 0; i < exponent; i++) {
27+ result *= base;
28+ }
29+ return result;
30+}
31+
32+module.exports = { add, multiply, divide, power };
+3−0
55 assert.strictEqual(math.multiply(4, 5), 20);
66 assert.strictEqual(math.divide(10, 4), 2.5);
77 assert.throws(() => math.divide(1, 0), RangeError);
8+assert.strictEqual(math.power(2, 10), 1024);
9+assert.strictEqual(math.power(5, 0), 1);
10+assert.throws(() => math.power(2, -1), RangeError);
811 console.log("all tests passed");