The Set Object

While practicing my algorithms and data structures, I came across a standard built in object for Javascript. The “Set” object. This handy guy lets you store unique values of any type in a collection of values! Its super handy when you are doing algorithms that want you to determine non-repeating or unique strings, etc.

I would start of by doing something like the following: const set = new Set();

Set has 4 Instance methods.

Set.add(value) : Appends value to the Set object. Returns the Set object with added value.

Set.has(value) : Returns a boolean asserting whether an element is present with the given value in the Set object or not.

Set.delete(value) : Removes the element associated to the value and returns a boolean asserting whether an element was successfully removed or not. Set.prototype.has(value) will return false afterwards.

Set.clear() : Removes all elements from the Set object.

Set has 1 instance property.

Set.size : Returns the number of values in the Set object.

With this basic knowledge you can solve leetcodes medium difficulty problem ?Longest Substring Without Repeating Characters”.

The question is as follows: Given a string s, find the length of the longest substring without repeating characters.

I solved it with the following code

Please check out MDN Source for a lot of examples and further information:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store