Hello!
I can’t find what is wrong with the code.
Errors:
-
After updateRecords(2548, “artist”, “”), artist should not be set
-
After updateRecords(2548, “tracks”, “”), tracks should not be set
Code:
function updateRecords(id, prop, value) {
if (prop !== “tracks” && value !== null) {
collection[id][prop] = value;
}
else if (prop === “tracks” && !(collection[id].tracks)) {
collection[id][prop] = [value];
}
else if (prop === “tracks” && value !== null) {
collection[id][prop].push(value);
}
else if (value === null) {
delete collection[id][prop];
}
return collection;
}