Record Collection - clarification

Tell us what’s happening:
The cod below compile and I was able to move to the next challenge. Looking some clarification on the solution code. The first nested if statement that will execute when passing value of prop is track and that the passing value is not an empty string, and this first nested if statement is " ```

if(collection[id][prop])
```". Is this if statement check if property tracks exist in the collection object which have the object of ids?  


**Your code so far**

```js

// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  if (prop !== "tracks" && value !=="") {
      if(value == ""){
        delete collection[id][prop];
      }else {
        collection[id][prop] = value;
      }
  }else if (prop === "tracks" && value!==""){
    var checkProp = collection[id].hasOwnProperty(prop);
        if(checkProp == false) {
      collection[id][prop] = [value];
    }else {
      collection[id][prop].push(value);
    }
  }else {
    delete collection[id][prop];
    }
  
  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection

Your code does not run as it has been copied and pasted into the code block. Based on your entry here, I wonder if you worked through this problem yourself or if you found parts of the solution elsewhere?

There are many conditions that the assignment which explains why there has to be so many conditional statements if you want to cram all the logic into one function. I’d reread through the assignment and write down the required conditions on a piece of paper and then go through the conditional statements and see which conditional checks which box of the assignment requirements.

Here’s a functional programming approach to the same problem that I think makes the solution much more understandable.

// Only change code below this line

function updateRecords(id, prop, value) {

  allChecks(id, prop, value);

  return collection;

}

function allChecks(id, prop, value){

  checkNotTrack(id,prop,value);

}

function checkNotTrack(id, prop, value){

  

  if(prop != "tracks" && value){ 

    collection[id][prop] = value;

    }

  else{ 

    hasTracks(id, prop, value);

    }

}

function hasTracks(id, prop, value){

  // ES6 object destructuring declares tracks variable 

  // and binds it to object collection[id]'s value of the tracks property.

  var{ tracks: tracks } = collection[id];

 

  switch(tracks instanceof Array){

    case true: collection[id]["tracks"] = collection[id]["tracks"].concat(value);

                console.log(collection[id]["tracks"])

                break;

    default:    collection[id]["tracks"] = [value];

                break;

                }

  // If I end up creating a record of a blank track above, it doesn't matter bc it's 

  // getting deleted anyways.

  if(!value) {deleteProp(id, prop);}  

}

function deleteProp(id, prop){

  delete collection[id][prop];

}