title: How to ignore spaces in string indexes and start with a capital letter on each word in a sentence
body: <p>Basically, I have this code, where I want to change a given string to <code>wEiRd CaSe</code>, alternate between indexes, for example: </p>
  
  <p>Starting from index <strong>0</strong> I want the letter to be capital, and then when the index got to an odd number, like 1, 3, 5, etc... I want to change it to uppercase. </p>
  
  <p>So: </p>
  
  <p>Stackoverflow should be <strong>StAcKoVeRfLoW</strong>, But I also want to work with strings, strings like this </p>
  
  <p><code>This is a test</code> should be: <strong>ThIs Is A TeSt</strong></p>
  
  <p>But my function returns : <strong>ThIs iS A TeSt</strong></p>
  
  <p>Here's my code:</p>
  
  <pre><code>"use strict";
  
  var weirdCase = function(string) {
      var characters = string.split("");
  
      characters.forEach(function(value, index, characters) {
          // If the index is even
          if (index % 2 == 0) {
              characters[index] = value.toUpperCase();
          } else {
              characters[index] = value.toLowerCase();
          }
      });
  
      return characters.join("");
  }
  </code></pre>
  
  <p>My question might be a bit misleading, I wanted to be wEiRd Case but also the first letter of the words to be capital, So I did this:</p>
  
  <pre><code>function toWeirdCase(string){
    return string.split(' ').map(function(word){
      return word.split('').map(function(letter, index){
        return index % 2 == 0 ? letter.toUpperCase() : letter.toLowerCase()
      }).join('');
    }).join(' ');
  }
  </code></pre>
  
  <p>Hope this helps someone</p>