This 'works' in my console.log, but doesn't pass test

Tell us what’s happening:
So, I put this together and I think it makes sense, and it looks like it works for the problem. I can switch out the test arguments and get the correct output. I looked at the solutions on the hint page… none of them actually use the arr array… I really wanted to keep that part intact… call me a rule follower.

I am using map and reduce because the problems leading up to this kind of put me in that mindset. I am pretty green though. This problem is the toughest one so far for me.

Thanks in advance.

   **Your code so far**

function whatIsInAName(collection, source) {
 var arr = [];
 // Only change code below this line
var sourceKeys = Object.keys(source);
var collected = collection.filter(obj => {
   return sourceKeys
     .map(function(key) {
       return obj.hasOwnProperty(key) && obj[key] === source[key];
     })
     .reduce(function(a, b) {
       return a && b;
     });
 });
 arr.push(collected);
console.log(arr);
 // 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36

Challenge: Wherefore art thou

Link to the challenge:

Is this jamming an array inside of an array?

2 Likes

Okay… Sorry for the multiple posts on this… Now I really understand what the issue is and your answer is much cleared. Now I am noticing the double bracket I was overlooking in my console output.

I will recheck solved… and I will hack at it a little more, but know that i can move on if i want…

Thanks again.

Edit: Spread is my friend! I could lose the collected variable altogether and make it much simpler, but again, just trying to color inside the lines.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.