Hello, i need help for 2 things. First i don’t know why the “return true;” is here:
function whatIsInAName( collection, source ) {
let keyNames = Object.keys(source);
let keyL = keyNames.length;
return collection.filter( function( obj ) {
for( let k = 0; k < keyL; k++ ) {
if( !obj.hasOwnProperty( keyNames[k] ) || obj[keyNames[k]] !== source[keyNames[k]] ) {
return false;
}
}
return true;
});
};
And secondly, this code is what i did at the beginning but i failed:
function whatIsInAName( collection, source ) {
var arr = [];
var keyNames = Object.keys(source);
var sourceL = keyNames.length;
for( prop in collection ) {
for( let k = 0; k < sourceL; k++ ){
if( collection[prop].hasOwnProperty( keyNames[k] ) ) {
if( collection[prop][keyNames[k]] == source[keyNames[k]] ) {
arr.push( collection[prop] );
}else {
arr = [];
k = sourceL;
}
}
}
}
return arr;
};
If some one could help me on both cases. Thanks