Skip to content

Instantly share code, notes, and snippets.

@joelnet
Created September 19, 2019 18:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelnet/3b0fb9ff43b654799398d425af8401a6 to your computer and use it in GitHub Desktop.
Save joelnet/3b0fb9ff43b654799398d425af8401a6 to your computer and use it in GitHub Desktop.
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