Who can help with filter?

<%= @topic_view.topic.title %>
<%= @topic_view.topic.average_rating %> <%= @topic_view.topic.posts.count { |p| !!p.custom_fields['rating'] } %>
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  let newArr = collection.filter(item => item.last === source.last );
  // Only change code above this line
  return newArr;

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

link : https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou
Who can help with filter to pass ? Can not filter the collection , filter does not working in my case (

you are not using source effectively, it will not have always a last property - plus it will also not have always only one property

I suggest you solve it first for one property in source - find how to make the check with whatever key-value is there

Hello ) can you hint what i should use to solve the problem with source ?

Should I add collection and source in one object ?

there are various ways to extract keys from an object - have you tried searching on the documentation?

things that were already in the curriculum are for…in loop and Object.keys()

Should I add collection and source in one object ?

what would you get by doing this?

The methods I used to solve this were:

  • Object.keys()
  • .hasOwnProperty()
  • .filter()
  • .map()
  • .reduce()

Thank you :slightly_smiling_face:

From object, I can get source as the last obj if objects are more than 2

you have already source as a separated object, you don’t need to put together source and collection

And how I can separated it ?

they are already separated
collection is an array, it contains objects
source is an object you need to use to select which elements in the array to keep