So whenever presented with a set of conditions, say 1, 2, 3, never just go if (1) else if (2) else if (3) because that often results in unnecessary code and/or unnecessary computing.
Think about this condition:
If value is an empty string, delete the given prop property from the album.
It makes a lot of sense to test this first doesn’t it? none of the other conditions want an empty string, and by testing this first, you eliminate additional checks later.
Now on to this:
value isn’t an empty string, update or set that album’s
so say you test this with
if (props != 'tracks') then you do not need to test if prop is ‘tracks’ later right? The only alternative to this if statement is if props is equal to ‘tracks’
So now we got 3 checks, first we see if value is an empty string, if not we see if props is not ‘tracks’, then else.
in the else you can put an if/else checking to see if the
object[id] already has the
Up until now it’s only been optimization, but here, with how you assign/change value to the
track property, is where you went wrong.
track is an array, meaning if the property does not exist, you should initialize it as an array, then push value into it, instead of changing it to a string (value)
if the property does exist, you should push value into it, instead of changing it to a string (value）as well.