Data Structures - Create a Set Class

Tell us what’s happening:
Unable to understand a syntax.

Your code so far
In the solution, the ‘add’ step has this.has(element)
But this doesn’t check inside the ‘dictionary’ type; I original code had this.dictionary.has(element)

I wonder how the given solution is correct and mine wrong. Any correct syntax/logic leeds?

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36

Challenge: Data Structures - Create a Set Class

Link to the challenge:

The has method is already put there for you to use by default in this test:

has(element) {
    return this.dictionary[element] !== undefined;
  }

You can see that inside it is checking the dictionary for the element and returning a true or false depending on if the element is there. The reason this.dictionary.has(element) would not work is dictionary doesn’t have a has method itself.

this.dictionary = {};
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.