Skip to content

Commit

Catch up with main

# Conflicts: # math.js

g1tbotcommitted Parents728f72bf111277Browse files
2 files+16−10/2 viewed
+13−1
1414 return a - b;
1515 }
1616
17−module.exports = { add, multiply, subtract };
17+/** Returns base raised to the whole-number exponent; throws a RangeError if exponent is negative. */
18+function power(base, exponent) {
19+ if (exponent < 0) {
20+ throw new RangeError("exponent must not be negative");
21+ }
22+ let result = 1;
23+ for (let i = 0; i < exponent; i++) {
24+ result *= base;
25+ }
26+ return result;
27+}
28+
29+module.exports = { add, multiply, subtract, power };
+3−0
44
55 assert.strictEqual(math.add(2, 3), 5);
66 assert.strictEqual(math.multiply(4, 5), 20);
7+assert.strictEqual(math.power(2, 10), 1024);
8+assert.strictEqual(math.power(5, 0), 1);
9+assert.throws(() => math.power(2, -1), RangeError);
710 console.log("all tests passed");