Tell us what’s happening:
I used spread operator on my code so If second arg has only values first arg already has, then the merged object should be the same as first arg. And Second arg will overwrite first arg properties of same name.
But I have an issue. When I run my code, I see in the output:
[ { first: 'Romeo', last: 'Montague' },
{ first: 'Mercutio', last: null },
{ first: 'Tybalt', last: 'Capulet' } ]
And I should return the objects that has the second arg which is the third object { first: "Tybalt", last: "Capulet" }
.
Could you help doing that!?
My code so far
function whatIsInAName(collection, source) {
var arr = [];
// Only change code below this line
let code = collection.filter(function (item) {
let obj = {...item, ...source};
return obj;
});
// Only change code above this line
return code;
}
console.log(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.16; rv:85.0) Gecko/20100101 Firefox/85.0
.
Challenge: Wherefore art thou
Link to the challenge: