Advertisement
AviEzerzer

Untitled

Aug 18th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Only change code below this line
  2. function updateRecords(id, prop, value) {
  3.   //check that id exists in collection
  4.   if (collection[id] === undefined) {
  5.     console.log(`id: ${id} is not in collection`);
  6.     return collection;
  7.   }
  8.  
  9.   let obj = collection[id];
  10.  
  11.   if (value == "") {
  12.     delete collection[id][prop];
  13.     return collection;
  14.   }
  15.  
  16.   switch (true) {
  17.     case prop === "tracks":
  18.       obj[prop] = obj[prop] || [];
  19.       obj[prop].push(value);
  20.       break;
  21.     case prop != "tracks":
  22.       obj[prop] = value;
  23.       break;
  24.   }
  25.  
  26.   collection[id] = obj;
  27.   return collection;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement