Skip to content

Basic JavaScript: Record Collection #41

@fasatrix

Description

@fasatrix

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions