Missing instructions and test case for Javascript Hashmap?

Link to the lesson



In step 3 the instructions read:

Add an if statement in the while loop that does a strict equality check of the current node’s .key and key . If the two keys are the same, overwrite the current node’s key and value properties with the key-value pair we want to store.

Right after that it reads:

Outside of the last if statement, write a condition that checks if the current node is the tail node. Check what Node methods are available to you in the Node.js file.

This is how I implemented that and it passed:

if(current.data.key === key){
   current.data = {key, value}
   current.setNextNode(new Node({key, value}))


I wonder why the instructions only ask us to break the loop if the second condition is met (step 5). Why should we continue the while loop if we’ve already overwritten a value?


I tested my code that passed all tests. The linked list seems to be polluted with old values:


If I break out of the loop if the first condition is met as well, the result seems to make more sense to me:

Did I miss a feature of Hashmaps or should the instructions and the test for passing be extended?