-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhatIsInAName.js
31 lines (27 loc) · 1011 Bytes
/
whatIsInAName.js
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
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
for (let collObj in collection) {
console.log(collection[collObj]);
}//can access this way
collection.forEach(collObj => {//or this way
console.log(collObj);
let flag = true;
let sourceArray = Object.entries(source);
sourceArray.forEach(keyValue => {
if (collObj[keyValue[0]] !== keyValue[1]) {
//keyValue[0]] gets the value based on the array keyValue[0] which is the name.
//keyValue[1] is the second element gives the value of the key
flag = false;
}
})
if (flag) {
arr.push(collObj);
}
})
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
//15 minutes