lang/subtract.js

  1. import { apply } from 'core/apply'
  2. /**
  3. * Replaces by the subtraction of the former number by the given number.
  4. * @function
  5. * @memberof lang
  6. * @param {Object} object The object to modify.
  7. * @param {Array|string} path The path of the property to set.
  8. * @param {number} subtrahend The number to subtract.
  9. * @return {Object} Returns the updated object.
  10. * @example subtract({ nested: { prop: 2000 } }, 'nested.prop', 336) // => { nested: { prop: 1664 } }
  11. * @since 1.0.0
  12. */
  13. const subtract = apply((value, subtraction) => Number(value) - Number(subtraction), { fixedArity: true })
  14. export { subtract }