Function updateRecords keeps updated your musical album collection represented by a JSON object. Each album has a unique id number as its key and several other properties like artist or tracks.
The purpose of the project is just personal learning.
You are get a JSON object collection representing a part of your musical album collection. Each album in the collection has a unique id number as its key and several other properties. Not all albums have complete information.
updateRecords function takes an object like collection, an id, a prop (like artist or tracks), and a value that it must update. The function must:
- Always return the entire object.
- If prop isn't tracks, and value isn't an empty string, it updates or set that album's prop to value.
- If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it. Uses hasOwnProperty to check first if the album has property "tracks".
- If prop is tracks, and value isn't an empty string, add value to the end of the album's existing tracks array.
- If value is an empty string, delete the given prop property from the album.
- Do the same on Python
- There's another possible solution here - must check it.
- Javascript ES6
NA - It's only coding examples, there's no setup.
Project is: in progress - Kept for reference.
Based on FreeCodeCamp's excercise Record Collection from subsection JavaScript Algorithms and Data Structures (Basic JavaScript section). I worked on this on year 2021.