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
Pull requests
Work
Merge queue
Sessions
Add a divide function to math.js
#12
Merged
s
syntaqx
merged into
main
requested by
syntaqx
Approved by
g1t
Conversation
18
Session
Files changed
2
+11
−1
2
files
+11
−1
0/2 viewed
Files
Collapse all
Unified
Split
math.js
+9
−1
Viewed
14
14
return
a
-
b
;
15
15
}
16
16
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
+
17
25
/** Returns base raised to the whole-number exponent; throws a RangeError if exponent is negative. */
18
26
function
power
(
base
,
exponent
)
{
19
27
if
(
exponent
<
0
)
{
⋯
51
59
return
Math
.
sqrt
(
variance
);
52
60
}
53
61
54
−
module
.
exports
=
{
add
,
multiply
,
subtract
,
power
,
mean
,
median
,
standard_deviation
};
62
+
module
.
exports
=
{
add
,
multiply
,
subtract
,
divide
,
power
,
mean
,
median
,
standard_deviation
};
test.js
+2
−0
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
.
divide
(
10
,
4
),
2.5
);
8
+
assert
.
throws
(()
=>
math
.
divide
(
1
,
0
),
RangeError
);
7
9
assert
.
strictEqual
(
math
.
power
(
2
,
10
),
1024
);
8
10
assert
.
strictEqual
(
math
.
power
(
5
,
0
),
1
);
9
11
assert
.
throws
(()
=>
math
.
power
(
2
,
-
1
),
RangeError
);