Tell us what’s happening:
hi everyone! i’m trying to apply what i learned with map
and filter
. I tried to put in the hints with the Object.keys
and hasOwnProperty
. Am i doing this wrong? Am i organizing this wrong? I’m getting an empty array!
Please help and explain what i’m doing wrong.
Your code so far
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
let sourceProps = Object.keys(source)
let filtered = collection.filter(function(obj) {
sourceProps.map(function(property){
return obj.hasOwnProperty(property) == true && obj[property] == source[property] ? obj : [];
})
})
console.log(filtered)
// 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_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
.
Challenge: Wherefore art thou
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou