Merge #5: Add subtract to math.js
2 files+7−10/2 viewed
| 9 | 9 | return a * b; | |
| 10 | 10 | } | |
| 11 | 11 | ||
| 12 | + | /** Returns a minus b. */ | |
| 13 | + | function subtract(a, b) { | |
| 14 | + | return a - b; | |
| 15 | + | } | |
| 16 | + | ||
| 12 | 17 | /** Returns base raised to the whole-number exponent; throws a RangeError if exponent is negative. */ | |
| 13 | 18 | function power(base, exponent) { | |
| 14 | 19 | if (exponent < 0) { | |
| ⋯ | |||
| 46 | 51 | return Math.sqrt(variance); | |
| 47 | 52 | } | |
| 48 | 53 | ||
| 49 | − | module.exports = { add, multiply, power, mean, median, standard_deviation }; | |
| 54 | + | module.exports = { add, multiply, subtract, power, mean, median, standard_deviation }; | |
| 1 | 1 | const assert = require("node:assert"); | |
| 2 | 2 | const math = require("./math"); | |
| 3 | + | assert.strictEqual(math.subtract(5, 3), 2); | |
| 3 | 4 | ||
| 4 | 5 | assert.strictEqual(math.add(2, 3), 5); | |
| 5 | 6 | assert.strictEqual(math.multiply(4, 5), 20); |