Record Collection turning out be hard and tuff

I was going through the quiz but it seems to be complicated as there are JSON.parse and JSON.stringigy but no prior knowledge or quiz of what those lines are doing is given.


// 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) {
  
  
  return collection;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36.

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

That’s a way to copy the object, you can actually investigate them separately from this challenge as they are there just for the tests. You don’t need to know those to solve the challenge

But here you can read about that:


MDN always confuses me.

Find an other source… still you can continue with the algorithm without having to worry about those

1 Like

The short version is that JSON.stringify() returns a string from whatever you pass in. JSON.parse() makes from strings objects or other data structures

You don’t need prior knowledge, see:

// Only change code below this line

JSON.parse/stringify work as explained above, but they have no relevance at this point in time to you doing the challenge: that line is there, as the comment above it says, for making a copy of the object for the tests.

@DanCouper I see this kind of question often regarding challenges which incorporate extra code which is strictly for the benefit of the tests. I have modified a couple of other challenges with PRs to remove these kinds of things, so I believe I can do the same for this challenge.

1 Like

Yea, I’ve noticed this a lot (obviously the ESNext challenges make up most of the complaints, but people miss or ignore the comments on the other ones).

Heh, I remember getting the exact same feeling on some of the code challenge sites, I can’t remember which one was the worst (Hackerrank maybe?), but on that one the “fill in the code here” bit was basically just gibberish “put the code in-between these very specific testing functions that we aren’t going to explain and make sure you use the interface we’ve written for JS instead of just writing the functions and using return but we’re not going to explain that either”