title: Palindrome challenge on Coderbyte
body: <p>I can't figure out why the following code does not work for the Coderbyte challenge where you have to test a string to see if it is a palindrome (the characters being the same when read in reverse as they are normally). I know there are better ways to write the code for the same result, but I still think this way should work (assuming no capital letters or non-alphabetic characters in the input string). But testing it doesn't yield the results I need. Here it is:</p>
  
  <pre><code>function Palindrome(str) { 
    var myArray = str.split("");
    for(var i = 0; i &lt; myArray.length; i++) {
      if(myArray[i] === " ") {
          myArray.splice(i, 1);
      }
    }
    var firstHalf = myArray.slice(0, Math.floor(myArray.length/2));
    var secHalf = myArray.slice(Math.ceil(myArray.length/2));
    secHalf.reverse();
    if(firstHalf === secHalf) {
      return true;
    }
    return false; 
  }
  </code></pre>
  
  <p>What I'm trying to do is split up the input string into an array, remove the spaces, specify the first and second halves of that array, reverse the second half, then compare if the two halves are equal. In cases where the number of characters in the string <code>str</code> is odd the middle character isn't taken into account since it shouldn't matter. And I did try asking this on Coderbyte but my question was not posted for some reason.</p>