-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhereforeArtThou.js
More file actions
32 lines (25 loc) · 940 Bytes
/
WhereforeArtThou.js
File metadata and controls
32 lines (25 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
for (var i = 0; i < collection.length; i++) {
var passesTest = true;
for (var property in source) {
if (!collection[i].hasOwnProperty(property) || source[property] !== collection[i][property]) {
passesTest = false;
}
//more clear logically to me but I think the above is more standard, the right of || being else if
// else if () {
// passesTest = false;
// }
}
if (passesTest === true) {
arr.push(collection[i]);
}
}
console.log(arr);
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null },
{ first: "Tybalt", last: "Capulet" }], { last: "Capulet" });