Tell us what’s happening:
Describe your issue in detail here.
I tried using the object.prototype.hasOwnProperty filter method. But it’s not working. Can you help me in completing this test. Your code so far
function whatIsInAName(collection, source) {
let arr = [];
// Only change code below this line
let filterArr = collection.filter(value => {
return value.hasOwnProperty(source);
})
arr.concat(filterArr);
// 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:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36.
I got stuck. Got only 2 tests correct at a time.
If use
arr = collection.filter(value => {
for(let i = 0; i < Object.keys(source).length; i++) {
return value.hasOwnProperty(Object.keys(source[i]));
}
}
return arr;
I got the 2nd and 3rd test correct.
And if I do,
arr = collection.filter(value => {
return Object.values(value).includes(Object.values(source).join(""));
})
I got only the 1st and last test correct.
Can you help me. Where am I doing wrong?