I solved the Wherefore art thou
challenge by deleting the collection (see bellow)
However I had to go to the extra step of filtering out null values (which I had to get from Stackoverflow). This isn’t very elegant and I am sure unecessary. Why does delete replace the objects in the array with Null? I haven’t found a simple way to remove elements from an object. Can someone give me some insights on what I am misunderstanding.
function whatIsInAName(collection, source) {
// What's in a name?
// Only change code below this line
for (var key in source) {
var i;
for (i = 0; i < collection.length; i++) {
if(collection[i][key] === source[key]){
}
else {
var index = collection.indexOf(collection[i]);
delete collection[index];
}
}
}
var arr = collection.filter(function(n){ return n != undefined });
// Only change code above this line
return arr;
}
whatIsInAName(whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 }));