Tell us what’s happening:
I was hoping someone can help me out. I can’t work out why my code isn’t working, have gone through it countless times and used debugger. I know it’s not the cleanest but to my mind should work. It passes all the test apart from the last one. Thanks in advance.
Your code so far
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
var props = Object.keys(source);
for (var i = 0; i < props.length; i++) {
for (var j = 0; j < collection.length; j++) {
if (!collection[j].hasOwnProperty(props[i]) || collection[j][props[i]] != source[props[i]]) {
collection.splice(i, 1);
if (collection.length > 0) {
j --;
}
}
}
}
arr = collection;
// 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/wherefore-art-thou