Code not passing and it should?! wherfort art thou challenge

so here is my code

	// noprotect
	function whatIsInAName(collection, source) {
	  // What's in a name?
	  var arr = [];   // append objects that pass checks here
	  var keys = Object.keys(source); // this stores key value for arg
	  var keysvalue = source[keys[0]]; // this stores variable assoicated with key
	  var key1 = keys[0];
	 
	  var length = collection.length; // this shows how many objects are in collection
	  
	  for(i = 0; i < length; i++ ) {  // loop through all objects
		for(j = 0; j < keys.length; j ++) { // loop through all keys
		  var newarr = []; // to create an array to push into arr
		  if(collection[i].hasOwnProperty(keys[j]) === false) { // if collecion doesn't have key stop what this isdoing
			break;
		  }
		  }
		arr = collection[i];
		
		}
		
	  // Only change code above this line
	  return arr;
	}

	whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });

I have tested this code against all the callenges and it passes, yet I am getting nothing but red X’s on the side. I am running into the same issue on the previous Roman Numeral challenge as well, any-one have any idea on what is going on here, also if you could, can you run it in your challenge and see if it passes there?

Although you are returning the correct results you are not returning an array. Check your code to see where you can change this.

1 Like

As Joel mentioned, you aren’t actually returning an array of objects, but a singular object.
Additionally, once you fix this, you’ll realize that a couple more problems come up; be sure that you are checking that the values of those keys are also equal once you’ve determined that all of the properties are present, but also be sure that the break statement is accomplishing what you desire.
Hope this helps. Let me know if you’re still stuck.

2 Likes

hey so I finally solved it by naming my loops to make sure it was breaking correctly and pushing the results into my array instead of setting it equal!, Thanks for your replies it really helped me understand what to do.

	function whatIsInAName(collection, source) {
	  // What's in a name?
	  var arr = [];   // append objects that pass checks here
	  var keys = Object.keys(source); // this stores key value for arg test
	  var keysvalue = source[keys[0]]; // this stores variable assoicated with key for test
	  var key1 = keys[0];
	 
	  var length = collection.length; // this shows how many objects are in collection
	  
	  outer:
	  for(var i = 0; i < length; i++ ) {  // loop through all objects
		
		for(var j = 0; j < keys.length; j ++) { // loop through all keys
		  var newarr = []; // to create an array to push into arr
		  if(collection[i].hasOwnProperty(keys[j]) === false) { // if collecion doesn't have key stop what this isdoing
			continue outer;
		  }
		  
		  else if(collection[i][keys[j]] !== source[keys[j]] ) {
			continue outer;
		  }
		 
		  }
		arr.push(collection[i]);
		
		}
		
	  // Only change code above this line
	  return arr;
	}
1 Like