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
console.log(newArr);
console.log(arr);
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 (
ilenia
August 13, 2019, 7:16am
2
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 ?
ilenia
August 13, 2019, 7:23am
5
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 ?
ilenia
August 13, 2019, 7:26am
7
what would you get by doing this?
The methods I used to solve this were:
Object.keys()
.hasOwnProperty()
.filter()
.map()
.reduce()
From object, I can get source as the last obj if objects are more than 2
ilenia
August 13, 2019, 8:43am
11
you have already source
as a separated object, you don’t need to put together source
and collection
And how I can separated it ?
ilenia
August 13, 2019, 8:58am
13
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