Last active
December 27, 2015 13:39
-
-
Save FGRibreau/7334567 to your computer and use it in GitHub Desktop.
Object::filter /for @4ntoin3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj = {a:1,b:2,c:9,d:10,f:5}; | |
Object.defineProperty(Object.prototype, "filter", { | |
value: function(f) { | |
return Object.keys(this).reduce(function(m, k) { | |
return f(this[k], k, this) ? (m[k] = this[k], m) : m; | |
}.bind(this), {}); | |
}, | |
enumerable: false, | |
writable: true | |
}); | |
obj.filter(function(v, k, obj){return v >= 5;}); | |
// Object {c: 9, d: 10, f: 5} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: writable:true is just here for testing