Skip to content

Commit

Catch up with main

# Conflicts: # math.js

g1tbotcommitted Parentscd36e15d6a7203Browse files
2 files+11−10/2 viewed
+9−1
1414 return a - b;
1515 }
1616
17+/** Returns a divided by b; throws a RangeError when b is 0. */
18+function divide(a, b) {
19+ if (b === 0) {
20+ throw new RangeError("Division by zero");
21+ }
22+ return a / b;
23+}
24+
1725 /** Returns base raised to the whole-number exponent; throws a RangeError if exponent is negative. */
1826 function power(base, exponent) {
1927 if (exponent < 0) {
5967 return Math.min(Math.max(value, min), max);
6068 }
6169
62−module.exports = { add, multiply, subtract, power, mean, median, standard_deviation, clamp };
70+module.exports = { add, multiply, subtract, divide, power, mean, median, standard_deviation, clamp };
+2−0
44
55 assert.strictEqual(math.add(2, 3), 5);
66 assert.strictEqual(math.multiply(4, 5), 20);
7+assert.strictEqual(math.divide(10, 4), 2.5);
8+assert.throws(() => math.divide(1, 0), RangeError);
79 assert.strictEqual(math.power(2, 10), 1024);
810 assert.strictEqual(math.power(5, 0), 1);
911 assert.throws(() => math.power(2, -1), RangeError);