title: How does this replaceAt function work?
body: <p>Could you please explain how this piece of code works? </p>
  
  <pre><code>String.prototype.replaceAt = function(index, character) {
      return this.substr(0, index) + character + this.substr(index+character.length);
  };
  
  
  function titleCase(str) {
      var newTitle = str.split(' ');
      var updatedTitle = [];
      for (var st in newTitle) {
          updatedTitle[st] = newTitle[st].toLowerCase().replaceAt(0, newTitle[st].charAt(0).toUpperCase());
      }
      return updatedTitle.join(' ');
  }
  
  titleCase("I'm a little tea pot");
  </code></pre>
  
  <p>Specifically, what exactly is passed onto to replaceAt (I get that it's passed an index, and a character that's converted to lowercase), but what does replaceAt DO with it? </p>
  
  <p>So, in the first iteration of the loop, it's passed replaceAt(0, i) right? Then what does replaceAt do with this? I just don't get this line:</p>
  
  <p><code>this.substr(0, index) + character + this.substr(index+character.length)</code></p>
  
  <p>I've already read this: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr</a>. I'm here because I don't understand that return statement and what exactly it's doing. </p>