Advertisement
RedNexX

JavaScript Doubt

Jul 14th, 2020
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Setup
  2. var collection = {
  3.   2548: {
  4.     album: "Slippery When Wet",
  5.     artist: "Bon Jovi",
  6.     tracks: [
  7.       "Let It Rock",
  8.       "You Give Love a Bad Name"
  9.     ]
  10.   },
  11.   2468: {
  12.     album: "1999",
  13.     artist: "Prince",
  14.     tracks: [
  15.       "1999",
  16.       "Little Red Corvette"
  17.     ]
  18.   },
  19.   1245: {
  20.     artist: "Robert Palmer",
  21.     tracks: [ ]
  22.   },
  23.   5439: {
  24.     album: "ABBA Gold"
  25.   }
  26. };
  27.  
  28. // Only change code below this line
  29. function updateRecords(id, prop, value) {
  30.   if (value === "") {
  31.     delete collection[id][prop];
  32.   } else if (prop === "tracks") {
  33.     collection[id][prop] = collection[id][prop] || [];
  34.     collection[id][prop].push(value);
  35.   } else {
  36.     collection[id][prop] = value;
  37.   }
  38.   return collection;
  39. }
  40.  
  41. updateRecords(5439, "artist", "ABBA");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement