freeCodeCamp features lots of challenges like “write an algorithm that does X”. I do write them, but then keep wondering whether I solved it “right”. Think performance and everything. For example, if I understand it correctly, this is basically a nested loop with the big O notation being n² which is a performance killer. I guess there’s a better way to do it. It’s a solution to this challenge
function whatIsInAName(collection, source) {
const objArr = Object.entries(source);
return collection.filter(colEl => {
return objArr.every(arrEl => colEl[arrEl[0]] === arrEl[1]);
});
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
It would be a great help if once you pass the tests, you’re shown a “best practice” solution written by freeCodeCamp staff. Should I tag someone?