Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Only change code below this line
- function updateRecords(id, prop, value) {
- //check that id exists in collection
- if (collection[id] === undefined) {
- return console.log(`id: ${id} is not in collection`);
- }
- //set prop if it does not exists
- if (collection[id][prop] === undefined) {
- if (prop === "tracks") {
- if (collection[id][prop] === undefined) {
- collection[id][prop] = [];
- } else {
- collection[id][prop] = null;
- }
- }
- }
- //assign value to non tracks key
- if (prop != "tracks" && value != "") {
- collection[id][prop] = value;
- }
- if (prop === "tracks" && value != "") {
- collection[id][prop].push(value);
- }
- if (value === "") {
- delete collection[id][prop];
- }
- /*** */
- return collection;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement