Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Why doesn't this work?
- function whatIsInAName(first, second) {
- var srcKeys = Object.keys(second);
- return (first.filter(function(obj) {
- for (var i = 0; i < srcKeys.length; i++) {
- return (!obj.hasOwnProperty(srcKeys[i]) ||
- obj[srcKeys[i]] !== second[srcKeys[i]] ? false : true);
- }
- }));
- }
- console.log(whatIsInAName([{"a": 1, "b": 2, "c": 3}], {"a": 1, "b": 9999, "c": 3}));
- /// --------------------- Why doesn't the above work, but the below does?
- // This works
- function whatIsInAName(collection, source) {
- var srcKeys = Object.keys(source);
- return collection.filter(function(obj) {
- for (var i = 0; i < srcKeys.length; i++) {
- if (!obj.hasOwnProperty(srcKeys[i]) ||
- obj[srcKeys[i]] !== source[srcKeys[i]]
- ) {
- return false;
- }
- }
- return true;
- });
- }
- console.log(whatIsInAName([{"a": 1, "b": 2, "c": 3}], {"a": 1, "b": 9999, "c": 3}));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement