Tell us what’s happening:
You start with an updateRecords
function that takes an object like collection
, an id
, a prop
(like artist
or tracks
), and a value
. Complete the function using the rules below to modify the object passed to the function.
- Your function must always return the entire object.
- If
prop
isn’ttracks
andvalue
isn’t an empty string, update or set that album’sprop
tovalue
. - If
prop
istracks
but the album doesn’t have atracks
property, create an empty array and addvalue
to it. - If
prop
istracks
andvalue
isn’t an empty string, addvalue
to the end of the album’s existingtracks
array. - If
value
is an empty string, delete the givenprop
property from the album.
Your code so far
function updateRecords(object, id, prop, value) {
if (prop !== "tracks" && value !==""){
collection[id][prop]= value ;
}
if (prop == "tracks" && !collection[id].hasOwnProperty("tracks")){
collection[id].tracks = [] ;
collection[id].tracks.push(value);
}
if (prop == "tracks" && value !==""){
collection[id][prop].push(value);
}
if (value === "") {
delete collection[id][prop];
}
return collection;
}
/ my code do not work in the final step -“delete the given prop
property from the album”.