@eluvio/elv-js-helpers
Version:
A collection of Javascript helper functions used by several Eluvio libraries.
15 lines (11 loc) • 536 B
JavaScript
const growth = require('./growth')
const curry = require('../Functional/curry')
// absRelChange :: Number -> Number -> Number
// Returns absolute value of change between two numbers, expressed as a proportion of the first value
// e.g. returns 0 if the values are the same, 0.5 if the second value is 50% larger
// Note that 0 is invalid for oldValue, the relative change is Infinity in that case
const absRelChange = curry(
(oldValue, newValue) => Math.abs(growth(oldValue, newValue))
)
module.exports = absRelChange