Unable to implement Set data structure

Tell us what’s happening:
I think I’ve written the code according to the given conditions but it seems to faill nearly all the tests.

Your code so far


class Set {
constructor() {
  // Dictionary will hold the items of our set
  this.dictionary = {};
  this.length = 0;
}

// This method will check for the presence of an element and return true or false
has(element) {
  return this.dictionary.indexOf(element) > -1;
}

// This method will return all the values in the set
values() {
  return Object.keys(this.dictionary);
}

add(item){
  if(!this.has(item)){
    dictionary.push(item);
    return true;
  }
  return false;
}

remove(item){
  var idx = this.dictionary.indexOf(item);
  if(idx === -1){
    return false;
  }else{
    return this.dictionary.splice(idx,1)[0];
  }
}

size(){
  return Object.keys(this.dictionary).length;
}
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0.

Challenge: Create a Set Class

Link to the challenge:

2 posts were merged into an existing topic: Can’t pass tests for Set data structure