You are given an object literal representing a part of your musical album collection. Each album has a unique id number as its key and several other properties. Not all albums have complete information.
You start with an updateRecords
function that takes an object literal, records
, containing the musical album collection, an id
, a prop
(like artist
or tracks
), and a value
. Complete the function using the rules below to modify the object passed to the function.
- Your function must always return the entire record collection object.
- If
prop
isn'ttracks
andvalue
isn't an empty string, update or set that album'sprop
tovalue
. - If
prop
istracks
but the album doesn't have atracks
property, create an empty array and addvalue
to it. - If
prop
istracks
andvalue
isn't an empty string, addvalue
to the end of the album's existingtracks
array. - If
value
is an empty string, delete the givenprop
property from the album. Note: A copy of therecordCollection
object is used for the tests.
Ff