array/filter.js

  1. import { applyArrayMethod } from './applyArrayMethod'
  2. /**
  3. * Replaces by an array of elements <code>predicate</code> returns truthy for.
  4. * @function
  5. * @memberof array
  6. * @param {Object} object The object to modify.
  7. * @param {Array|string} path The path of the property to set.
  8. * @param {function} predicate The function invoked per iteration.
  9. * @return {Object} Returns the updated object.
  10. * @example filter({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', v => v % 2) // => { nested: { prop: [1, 3] } }
  11. * @see {@link https://mdn.io/Array.prototype.filter|Array.prototype.filter} for more information.
  12. * @since 1.0.0
  13. */
  14. const filter = applyArrayMethod('filter', { mutating: false })
  15. export { filter }