-
Notifications
You must be signed in to change notification settings - Fork 16
Fixes clamp bug #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes clamp bug #36
Conversation
src/functions/clamp.js
Outdated
@@ -21,14 +21,15 @@ const findClamp = (a, min, max) => { | |||
*/ | |||
|
|||
export function clamp(a, min, max) { | |||
if (!min) return a; | |||
if (min === null) return a; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be min == null
? I'm not sure what you're testing for here, explicitly null, or just that something was passed in. A test case would help too.
Same with the max
check below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be checking if any value was passed in for min
, but I realize we want the same check for max
.
@w33ble I changed up the logic a bit in the |
if (max === null) | ||
throw new Error("Missing maximum value. You may want to use the 'min' function instead"); | ||
if (min === null) | ||
throw new Error("Missing minimum value. You may want to use the 'max' function instead"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏆 for hints to the user about what they might want to use instead!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Clamp uses falsy checks for
min
andmax
which causes problems when you pass in0
for either parameter. This changes them to checks for null equality instead and adds a few unit tests.