Hi,
I almost have this solved, it returns the right results, but maybe of the wrong type ? I hope someone can help
Thanks
Your code so far
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
let hasProp="";
let eachKey = [];
let count = 0;
for(let index in collection){
for(let key in source){
hasProp = collection[index].hasOwnProperty(key);
if(hasProp){
if(collection[index][key] === source[key]){
eachKey.push(key);
}
}
++count;
}
if(eachKey.length===count){
Object.entries(collection[index]).forEach(([key, value])=>{
arr.push(`${key}: ${value}`);
});
}
eachKey.splice(0,eachKey.length);
count=0;
}
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; rv:69.0) Gecko/20100101 Firefox/69.0
.
Challenge: Wherefore art thou
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou