@eluvio/elv-js-helpers
Version:
A collection of Javascript helper functions used by several Eluvio libraries.
21 lines (17 loc) • 718 B
JavaScript
const absRelChange = require('./absRelChange')
const curry = require('../Functional/curry')
// // snapRelative :: Number -> Number -> Number -> Number
// // Returns returns a standard value if testValue is within a proportional tolerance, measured relative to a
// // standard value, otherwise returns testValue unchanged
// const snapWithinTolerance = (tolerance, standardValue, testValue) =>
// Math.abs(change(standardValue, testValue)) <= tolerance ?
// standardValue :
// testValue
const snapRelative = curry(
(maxAbsRelChange, snapToValue, testValue) =>
absRelChange(snapToValue, testValue) <= maxAbsRelChange ?
snapToValue :
testValue
)
module.exports = snapRelative