Closed lars-jpeg closed 2 years ago
Seems like your curried function isn't quite taking advantage of the closure.
I'd move clone
to the outer function body:
export const divide =
(config) => {
const BigNumberWithConfig = BigNumber.clone(config)
return (dividend, divisor) => {
if (!isNumber(dividend) || !isNumber(divisor) || divisor === 0) {
return 0
}
const result = new BigNumberWithConfig(dividend).dividedBy(divisor).toNumber()
return result
}
}
Wow @shuckster . Gotta say I wasn't even aware of this pattern. Today I learned something new! That looks really handy.
I'm a fan of a functional programming style and I was wondering would it be wasteful to create a new BigNumber constructor for every calculation with the provided config? Below is an example that tries to achieve a pure functional style. Is .clone() well suited for this purpose?