title: Longest substring without repeating characters throwing a run time error?
body: <p><strong>My code works for many other test cases except for <a href="https://leetcode.com/submissions/detail/531439156/testcase/" rel="nofollow noreferrer">this</a></strong></p>
  <p>It runs a runtime error so I was wondering if someone could help me figure out why. Thanks, here's the code:</p>
  <pre><code>    if(s.length &lt;= 1){
          return s.length
      }
      let lengths = []
      s = s.split('')
  
  function run(index){
      if(index === s.length){
          lengths.push(s.slice(0,index).length)
          return
      }
      if(s.slice(0,index).indexOf(s[index]) &gt;= 0){
          lengths.push(s.slice(0,index).length)
          s.splice(0, s.slice(0,index).indexOf(s[index]))
          if( s.slice(0,index).indexOf(s[index]) === 0 ){
              s.splice(0,1)
          }
          index = 0
      
      }
      run(index+1)   
   }
      run(0)
  
      return Math.max(...lengths)
  };
  </code></pre>