title: Javascript revert part of string not working?
body: <p>Working on this <a href="https://leetcode.com/problems/reverse-words-in-a-string" rel="nofollow noreferrer">reverse words in string</a></p>
  
  <p>I tried to revert part of the string, given the input string, start_index, end_index, but it seems no effect.</p>
  
  <pre><code>var myrev = function(str, s, e) {
      let tmp;
      while(s&lt;e) {
          tmp = str[s];        
          str[s] = str[e];        
          str[e] = tmp;
  
          s++;
          e--;
      }
  
      return str;
  }
  </code></pre>
  
  <p>full code </p>
  
  <pre><code>// revert the words in this string: " the  sky is   blue "
  var reverseWords = function(s) {
      let a = s.trim().replace(/\s+/g, ' ');
      a = a.split('');
  
      // s === "eulb si yks eht"
      s = a.reverse().join('');
  
      let i, j, ind;
      ind = s.indexOf(' ', 0);
      i=0;
      j=ind-1;
  
      // expect s === "blue si yks eht", but still "eulb si yks eht", why???????
      s = myrev(s, i, j);
  
      console.log(s)
  };
  
  
  var myrev = function(str, s, e) {
      let tmp;
      while(s&lt;e) {
          tmp = str[s];        
          str[s] = str[e];        
          str[e] = tmp;
  
          s++;
          e--;
      }
  
      return str;
  }
  </code></pre>
  
  <p>Does it seem I need to pass a string as a reference?</p>