Created
September 19, 2019 18:14
-
-
Save joelnet/3b0fb9ff43b654799398d425af8401a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pipe = require('ramda/src/pipe') | |
const curry = require('ramda/src/curry') | |
const clampA = (min, max, value) => { | |
let newValue = Number(value) | |
newValue = Math.min(max, newValue) | |
newValue = Math.max(min, newValue) | |
return newValue | |
} | |
const clampB = (min, max, value) => | |
Math.max(min, Math.min(max, Number(value))) | |
const clampC = (min, max, value) => pipe( | |
Number, | |
num => Math.min(max, num) | |
num => Math.max(min, num) | |
) | |
const mathMin = curry(Math.min) | |
const mathMax = curry(Math.max) | |
const clampD = min => max => pipe( | |
Number, | |
mathMin(max) | |
mathMax(min) | |
) | |
const clampE = (min, max, num) => num | |
|> Number | |
|> Math.min(max, ?) | |
|> Math.max(min, ?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment