What am i missing guys on Where art Thou challenge?

I am sensing I am missing smth very obvious so please hint at the mistake as to why I am not getting any output from d, but an empty array?

Any help is appreciated

  // Only change code below this line
  var o = Object.entries(source);
  // Only change code above this line
  var a = Object.entries(collection);
  
 
  for(i = 0; i < Object.keys(collection).length; i++){
    arr.push(collection[i]);
  }
  
 
  var keySource =  Object.keys(source);
  var d = 0;
 
  
  for(var z = 0; z < arr.length; z++){
     for(var j = 0; j < keySource.length; j++){
    if(arr[z][keySource[j]] == source[keySource[j]]){
    d.push(arr[z]);
}

      }  
    return d;

  }

}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });

Your code has several issues.

#1) You are missing a closing }. Hint: It is somewhere in the following code:

  for(var z = 0; z < arr.length; z++){
     for(var j = 0; j < keySource.length; j++){
    if(arr[z][keySource[j]] == source[keySource[j]]){
    d.push(arr[z]);
}

      }  

It would be easier to recognize, if you properly indented your code.

#2) You are referencing a variable named arr, but you have not declared it in your function.

#3) You have initialized a variable named d to the value 0, but then in your inner for loop, you are trying to push arr[z] in it like it is an array. You can only use push on arrays, and d contains the number 0.

#4) You have two variables o and a which you initialize in the first part of your code, but you never use them. What is the purpose of these two variables?

It appears you have not quite figured out your algorithm (logic steps) to solve this challenge, because it is not clear the direction you are heading with your current code. Maybe if you explained to us what your algorithm is, we can better guide you to a solution.

EDIT: I changed the title of your topic to reflect which challenge you were asking about, because you did not specify the challenge name in your original post text.

Thanks, sorry must have posted the incorrect version of the code I had initially, apologies.
That is the one I meant to post. The only thing I actually missed out on here is the return statement that came too early originally.

I can pass the first two checks, but not the last two. I can see with the output checks that my conditions are way too sloppy as any match is enough to put the element in the final d array. I guess I more or less understand what I need to change now.

Thanks for the help again! A good constructive answer. Apologies for posting the stuff that was not what I intended to post which caused a couple of extra issues you picked up on that were not meant to be there.

Cheers

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  var o = Object.entries(source);
  // Only change code above this line
  var a = Object.entries(collection);
  
 
  for(i = 0; i < Object.keys(collection).length; i++){
    arr.push(collection[i]);
  }
  
 
  var keySource =  Object.keys(source);
  var d = [];
 
  
  for(var z = 0; z < arr.length; z++){
     for(var j = 0; j < keySource.length; j++){
    if(arr[z][keySource[j]] == source[keySource[j]]){
    d.push(arr[z]);
}

      }  

  }

      return d;

One other suggestion, which will help you out in the long run and others reading your code:

Make your variable names reflect what data is contained in them. For example, instead of having a variable named d which gives no context to what it holds, name it matchedObjects or something like that. The same applies to the other variables.

Thank you, of course you are right, this is the one thing every programmer should bear in mind.

Cheers