Tell us what’s happening:
Describe your issue in detail here.
Hello, there. I am a beginner, my code don`t have any trouble passing the run test.
The thing is when I read the solutions in the get help section, all the solutions are using nested methods and functions, trying to keep the code really short and clean.
Should I try to avoide writing code like am doing it right now? focuse on trying to keep my code really short. Or will it come naturally when I am more experienced with javascript??
Thanks.
**Your code so far**
function whatIsInAName(collection, source) {
var arr = [];
// Only change code below this line
let targetKeyNum = Object.keys(source).length;
let keys = Object.keys(source);
let vals = Object.values(source);
// Number of keys match
function matchingTimes(testList) {
let keyMatchTimes = 0;
let dList = Object.keys(testList);
for (let b = 0; b < targetKeyNum; b++) {
let testKey = keys[b];
if (dList.includes(testKey)) {
keyMatchTimes += 1;
}
}
return (keyMatchTimes == targetKeyNum) ? true : false;
}
// Number of values match
function valueMatch(item) {
let valMatchTimes = 0;
for (let i = 0; i < targetKeyNum; i++) {
if (item[keys[i]] == vals[i]) {
valMatchTimes += 1;
}
}
return (valMatchTimes == targetKeyNum) ? true : false;
}
let keyMatch = collection.filter(item => matchingTimes(item));
let valMatch = keyMatch.filter(item => valueMatch(item));
arr = valMatch;
// 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/91.0.4472.164 Safari/537.36 OPR/77.0.4054.277
Challenge: Wherefore art thou
Link to the challenge: