Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. function whatIsInAName(collection, source) {
  2. // What's in a name?
  3. var arr = [];
  4. // Only change code below this line
  5. var keys = Object.keys(source);
  6. // Filter array and remove the ones that do not have the keys from source.
  7. arr = collection.filter(function(obj) {
  8. //Use the Array method every() instead of a for loop to check for every key from source.
  9. return keys.every(function(key) {
  10. // Check if the object has the property and the same value.
  11. return obj.hasOwnProperty(key) && obj[key] === source[key];
  12. });
  13. });
  14.  
  15.  
  16. // Only change code above this line
  17. return arr;
  18. }
  19.  
  20. whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement