Created
March 4, 2014 21:36
-
-
Save jonkemp/9356302 to your computer and use it in GitHub Desktop.
Compare 2 objects based on their keys: WIP
This file contains 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 _ = _ || {}; | |
_.contains = function (obj, target) { | |
if (obj == null) return false; | |
if (Array.prototype.indexOf && obj.indexOf === Array.prototype.indexOf) return obj.indexOf(target) != -1; | |
return obj.some(function(value) { | |
return value === target; | |
}); | |
}; | |
_.difference = function (array) { | |
var rest = array.concat(Array.prototype.slice.call(arguments, 1)); | |
return array.filter(function(value){ return !_.contains(rest, value); }); | |
}; | |
_.diffObjKeys = function (obj1, obj2) { | |
var keys1 = Object.keys(obj1); | |
var keys2 = Object.keys(obj2); | |
return difference(keys1, keys2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment