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 clamp function to math.js
#24
Merged
s
syntaqx
merged into
main
requested by
syntaqx
Approved by
g1t
Conversation
16
Session
Files changed
2
+14
−1
2
files
+14
−1
0/2 viewed
Files
Collapse all
Unified
Split
math.js
+9
−1
Viewed
67
67
return
Math
.
sqrt
(
variance
);
68
68
}
69
69
70
−
module
.
exports
=
{
add
,
multiply
,
subtract
,
divide
,
mod
,
power
,
mean
,
median
,
standard_deviation
};
70
+
/** Returns value limited to the range [min, max]; throws a RangeError if min is greater than max. */
71
+
function
clamp
(
value
,
min
,
max
)
{
72
+
if
(
min
>
max
)
{
73
+
throw
new
RangeError
(
"
min must not be greater than max
"
);
74
+
}
75
+
return
Math
.
min
(
Math
.
max
(
value
,
min
),
max
);
76
+
}
77
+
78
+
module
.
exports
=
{
add
,
multiply
,
subtract
,
divide
,
mod
,
power
,
mean
,
median
,
standard_deviation
,
clamp
};
test.js
+5
−0
Viewed
24
24
for
(
const
fn
of
[
math
.
mean
,
math
.
median
,
math
.
standard_deviation
])
{
25
25
assert
.
throws
(()
=>
fn
([]),
TypeError
);
26
26
}
27
+
assert
.
strictEqual
(
math
.
clamp
(
5
,
0
,
10
),
5
);
28
+
assert
.
strictEqual
(
math
.
clamp
(
-
5
,
0
,
10
),
0
);
29
+
assert
.
strictEqual
(
math
.
clamp
(
15
,
0
,
10
),
10
);
30
+
assert
.
strictEqual
(
math
.
clamp
(
3
,
3
,
3
),
3
);
31
+
assert
.
throws
(()
=>
math
.
clamp
(
1
,
10
,
0
),
RangeError
);
27
32
console
.
log
(
"
all tests passed
"
);