Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic JavaScript: Record Collection #41

Open
fasatrix opened this issue Jun 16, 2018 · 1 comment
Open

Basic JavaScript: Record Collection #41

fasatrix opened this issue Jun 16, 2018 · 1 comment

Comments

@fasatrix
Copy link

fasatrix commented Jun 16, 2018

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;
}
@pynchmeister
Copy link

the above worked fine, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants