My-FreeCodeCamp-Code icon indicating copy to clipboard operation
My-FreeCodeCamp-Code copied to clipboard

Basic JavaScript: Record Collection

Open fasatrix opened this issue 7 years ago • 1 comments

Hey there, you should change the code in order to cover this requirement: if prop is "tracks" but the album doesn't have a "tracks" property, create an empty array before adding the new value to the album's corresponding property.

Something like the following should work:

function updateRecords(id, prop, value) {
  if (value === '') {
    delete collection[id][prop];
  } else if (prop !== 'tracks') {
    collection[id][prop] = value;
  } else {
     !collection[id].hasOwnProperty('tracks') ? collection[id][prop] = [] 
                                              : collection[id][prop];
     collection[id][prop].push(value);
  }   
  return collection;
}

fasatrix avatar Jun 16 '18 04:06 fasatrix

the above worked fine, thank you.

pynchmeister avatar Sep 19 '18 22:09 pynchmeister