Created
December 28, 2012 20:45
-
-
Save lgsunnyvale/4401689 to your computer and use it in GitHub Desktop.
javascript in and filter_keys
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 __in__ = function(elem, array){ | |
| array.forEach(function(item) { | |
| if (item === elem) return true; | |
| }); | |
| return false; | |
| }; | |
| var __filter_keys = function(obj, filter) { | |
| var result = {}; | |
| var extraKeys = $.grep(Object.keys(obj), function(el, i) { | |
| return !(__in__(el, filter)); | |
| }); | |
| if (extraKeys.length > 0) { | |
| extraKeys.forEach(function(key) { | |
| result[key]=obj[key]; | |
| }); | |
| } | |
| return result; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment