Could somebody help explain this to me: NEW

Well, I see that this challenge is a bit tricky.
I will try to explain it:

The first line is the declaration, the function will take three arguments, id(the id of the collection in the JSON object), “prop” is the property, it could be “artist”, “album” or “tracks”, and value. The function will take the id an the property and will update that property with the new “value”, that given in the function call.

function updateRecords(id, prop, value)

Now you will test something. First the function tests if the value is an empty string. If that is true it will delete these property from the collection that you supply. this part handles the cases were you want delete some value in property :

 if (value===""){
delete collection[id][prop]
}

If that is not true(you are supplying some value) then the function will test if the property is “tracks”:

 else if (prop===“tracks”){
collection[id][prop]=collection[id][prop] || []
collection[id][prop].push(value)
}

I explain in detail this in the follow link:

http://forum.freecodecamp.org/t/record-collection-question/382808/4?u=rigo-villalta

If the property is not “tracks” and value is not empty, the function simply updates the value in the wanted property:

 else{
 collection[id][prop]=value
 }

Finally you return all the collection updated:

return collection

I hope it helps.

1 Like