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) {
- console.log(`id: ${id} is not in collection`);
- return collection;
- }
- let obj = collection[id];
- if (value == "") {
- delete collection[id][prop];
- return collection;
- }
- switch (true) {
- case prop === "tracks":
- obj[prop] = obj[prop] || [];
- obj[prop].push(value);
- break;
- case prop != "tracks":
- obj[prop] = value;
- break;
- }
- collection[id] = obj;
- return collection;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement