I just solved the record collection challenge after many failed attempts. I feel I still need to revisit the solution to really understand what was going on, and especially wrap my head around the delete operator.
To get everything green I had to used the delete operator in the very last ELSE statement to delete any submissions what had empty values.
In every other condition where I have valid data in the function call I will consequently make some change to the collection object. But when have a function call with incomplete data such as an empty track.
updateRecords(2548, "tracks", "")
I think that I just I need to leave the collection object alone. and exit the function with.
return collection;
and be done with it. I can just skip the object manipulation process entirely. But in order to pass the exercise I needed to to delete the empty property like this.
delete collection[id][prop];
But since I don’t add any property in the function when the value is empty , why would I then need to delete a property that, to my knowledge, I never added in the first place? I assume the property and value only exist in the function call, but never touch the object unless I code it so. It this a matter of how the test itself is designed, or is there a good reason for developers to use delete in this manner in similar if else statements that manipulate an object?