title: Longest Substring without repeating characters issue with edge case
body: <p><em>I was trying to solve this problem: Longest substring without repeating characters. The issue is, it's failing in couple test cases, I don't know how to fix it. I would need your help to see where I'm going wrong.</em></p>
  
  <p><strong>Question:</strong></p>
  
  <blockquote>
    <p>Given a string, find the length of the longest substring without
    repeating characters.</p>
    
    <p>Examples:</p>
    
    <p>Given "abcabcbb", the answer is "abc", which the length is 3.</p>
    
    <p>Given "bbbbb", the answer is "b", with the length of 1.</p>
    
    <p>Given "pwwkew", the answer is "wke", with the length of 3. Note that
    the answer must be a substring, "pwke" is a subsequence and not a
    substring.</p>
  </blockquote>
  
  <p><strong>This is my code:</strong></p>
  
  <pre><code>function longestSubString(arr){
      let localSum=0,globalSum=0;
  
      let set = new Set();
  
      for(let i=0; i&lt;arr.length; i++){
          let current = arr[i];
  
          //if the key is present in the store.
          if(set.has(current)){
              set.clear();
              localSum = 1;
              set.add(current);
          } else {
              localSum +=1;
              set.add(current);
          }
  
          if(globalSum &lt; localSum){
              globalSum = localSum;
          }
  
      }
  
      return globalSum;
  }
  </code></pre>
  
  <p><strong>Tests:</strong></p>
  
  <pre><code>let test = "abcabc"; //returns 3 - correct
  let test2 = "bbb"; //returns 1 - correct
  
  
  let test5 = "dvdf"; //returns 2 - INCORRECT! it should return 3 (i.e for vdf) since I'm doing set.clear() I'm not able to store previous elements.
  
  longestSubString(test5); //incorrect
  </code></pre>
  
  <p><strong>Live:</strong></p>
  
  <pre><code>https://repl.it/Jo5Z/10
  </code></pre>