The 1st two tests are running but the 3rd and 4th are not . This doesn’t work where the source has two or more iterations.
Please help as to how i should approach further .Thanks in advance.
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
var x=Object.keys(source);
//var y=source.hasOwnProperty(x);
for(var i=0;i<collection.length;i++){
if(collection[i].hasOwnProperty(x)){
if(collection[i][x]==source[x]){
arr.push(collection[i]);
}
}
}
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
.
Link to the challenge: