Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. Object.prototype.filter = function(fn) {
  2. return Object.keys(this)
  3. .filter( key => {
  4. const result = fn(key, this[key], this);
  5. return result === false || result === null;
  6. })
  7. .reduce((obj, key) => Object.assign(obj, {[key]: fn(key, this[key], this)}),
  8. {});
  9. }
  10.  
  11. Object.prototype.map = function(fn) {
  12. return Object.keys(this)
  13. .reduce((obj, key) => Object.assign(obj, {[key]: fn(key, this[key], this)}),
  14. {});
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement