Hello,
In this case: ( recordCollection, 2548, “tracks”, “”)
my solution doesn’t works.
The program display: " After “updateRecords(recordCollection, 2548, “tracks”, “”)”, tracks should not be set.
function updateRecords(records, id, prop, value) {
if ( prop != 'tracks' ) {
if (value != '') {
records[id][prop] = value;
} else if (records[id].hasOwnProperty(prop)) {
delete records[id][prop];
}
} else if (records[id].hasOwnProperty(prop)&& value != '') {
records[id][prop].push(value);
} else { // what ever value. Because if value is an empty string and I remove the tracks of id 2548, the result should be tracks: [] as the FCC solution.
records[id][prop] = [value];
}
See the coment.
And with the FCC solution:
function updateRecords(records, id, prop, value) {
if (prop !== 'tracks' && value !== "") {
records[id][prop] = value;
} else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === false) {
records[id][prop] = [value]; // what ever value, even if value is an empty string. for exemple if I remove the tracks of Id 2548, the result will be tracks: []
} else if (prop === "tracks" && value !== "") {
records[id][prop].push(value);
} else if (value === "") {
delete records[id][prop];
}
return records;
}
See the coment.
What is the différence ?
I don’t understand why my solution doesn’t works in this case.