Hey,
I’m working on this for several hours (Wherefore art thou intermediate algorithm challenge) and still can’t get a pass on the first test (3 others are green).
The problem is with comparing the values of given properties in else if
. It doesn’t work. The flag should be changed to false
but it somehow isn’t. What’s wrong?
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
for (var i = 0; i< collection.length; i++)
{
var flag = true;
for (var prop in collection[i]) {
for (var propS in source) {
if (collection[i].hasOwnProperty(propS) === false)
{
flag = false;
}
else if (source.propS != collection[i].props )
{
flag = false;
}
}
}
if (flag === true)
{
arr.push(collection[i]);
}
}
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Somebody advised me to use filter() method, but maybe there’s a way without it?