Getting no progress on solving,
Here are the requirements
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.
Note: A copy of the collection
object is used for the tests.
Here is my solution with 0 successes… Help
// Setup
var collection = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
2468: {
albumTitle: '1999',
artist: 'Prince',
tracks: ['1999', 'Little Red Corvette']
},
1245: {
artist: 'Robert Palmer',
tracks: []
},
5439: {
albumTitle: 'ABBA Gold'
}
};
// Only change code below this line
function updateRecords(object, id, prop, value) {
if (prop !== "tracks" && value !== "") {
collection[id][prop] = value;
} else if (prop === "tracks" && !condition[id].hasOwnValue("tracks")) {
collection[id].album = [];
} else if (prop === "tracks" && value !== "") {
collection[id].tracks.push(value);
} else if (value === ""){
delete collection[id].album[prop];
}
return object;
}
updateRecords(collection, 5439, 'artist', 'ABBA');
Anything would be super helpful.