Skip to content
⌘K
Explore
Download
Docs
Sign in
Sign up
flagon-io
/
automation-lab
public
Star
0
Scratch repository for testing automations.
Overview
Code
Issues
1
Pull requests
Workflows
Deployments
Insights
Files
Commits
Branches
Tags
Releases
Compare
Commit
Catch up with main
# Conflicts: # math.js
g1t
bot
committed
1w ago
Parents
728f72b
f111277
Browse files
fd4e0bcf4a93
2
files
+16
−1
0/2 viewed
Files
Collapse all
Unified
Split
math.js
+13
−1
View
Blame
Viewed
14
14
return a - b;
15
15
}
16
16
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 };
test.js
+3
−0
View
Blame
Viewed
4
4
5
5
assert.strictEqual(math.add(2, 3), 5);
6
6
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);
7
10
console.log("all tests passed");