Create-a-map-data-structure-test-case-failing

Tell us what’s happening:
add method is assigning value to the collection but it not passing test case.

Your code so far



var Map = function() {
  this.collection = {};
  // change code below this line
  
  this.add = function(key,value) {
    this.collection[key] = value;
  };
  this.remove = function(key) {
    delete this.collection[key];
  };
  this.get = function(key) {
    return this.collection[key];
  };
  this.has = function(key) {
    return this.collection[key] !== undefined;
  };
  this.size = function() {
    return Object.keys(this.collection).length;
  };
  this.values = function() {
    let result = [];
    for(let i in this.collection) {
      if(this.has(i)) {
        result.push(this.collection[i]);
      }  
    }
    return result;
  };
  this.clear = function() {
    this.collection = {};
  };
  
  // change code above this line
};

Your browser information:

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

Link to the challenge:

I have the same code for add method and it’s passing now. You can try again.

1 Like