// Only change code below this line
function updateRecords(id, prop, value) {
var album = collection[id];
// Empty value param: remove the prop
if (~value) {
delete album[prop];
}
// Update tracks list
if (prop === "tracks") {
if (value) {
if (~album.hasOwnProperty('tracks')) {
album.tracks =[];
}
album.tracks.push(value);
}
}
// Update anything else
else {
if (value) {
album[prop] = value;
}
}
return collection;
}
The above is my solution for the Record Collection challenge but it seems to fail the test for
updateRecords(2468, "tracks", "Free")
for which tracks should have 1999 as the first element.
When I debugged, it seems like the line:
album.tracks =[];
is being run even though the id 2468 has a property called tracks and the conditional should be preventing the above from running.