Update math.js to include min, max, and clamp functions #339
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Include of simple math helpers for inline calculations. All support Number types of Int and Float, but not edge case numbers such as NaN, +-infinity, or undefined.
Min: given
A
andB
return the smaller of the two on a standard number line.Max: given
A
andB
return the larger of the two on a standard number line.Clamp: given
test
,min
andmax
return the tested value if it falls within the range ofmin
andmax
such thatmin < test < max
is satisfied on a standard number line. If the constraint is not satisfied, return the closest bounding constraint.Note for implementation
File:
thirdParty.js
in directoryhelpers/thirdParty.js
will also need line 71 to be modified to include the string names of the new functions.include: ['add', 'subtract', 'divide', 'multiply', 'floor', 'ceil', 'round', 'sum', 'avg', 'min', 'max', 'clamp']
What? Why?
Because these math functions are currently missing from the standard library.
How was it tested?
None required, mirror of existing functionhelper.add
with math operations swapped for logical operations.Uses inline ternary operators for state evaluation.Edit:
Adding Of Testing Protocol in comment:
cc @bigcommerce/storefront-team