index.js 400 B

12345678910111213141516171819
  1. 'use strict';
  2. module.exports = (object, predicate) => {
  3. const result = {};
  4. const isArray = Array.isArray(predicate);
  5. for (const [key, value] of Object.entries(object)) {
  6. if (isArray ? predicate.includes(key) : predicate(key, value, object)) {
  7. Object.defineProperty(result, key, {
  8. value,
  9. writable: true,
  10. enumerable: true,
  11. configurable: true
  12. });
  13. }
  14. }
  15. return result;
  16. };