title: JavaScript function to reverseArrayInPlace -- Eloquent JavaScript Ch4
body: <p>Can anyone show me where I'm going wrong with this function on reversing arrays? It's an exercise from the  book <em><a href="http://eloquentjavascript.net/04_data.html#c_F3JsLaIs+m" rel="nofollow">Eloquent JavaScript</a></em>. </p>
  
  <p>I've checked my variables through the console and the loop seems to be working but at the end the array indexes don't seem to get overwritten and I don't understand why!</p>
  
  <p>The answer I'm looking for is:</p>
  
  <pre><code>var arrayValue = [1, 2, 3, 4, 5];
  reverseArrayInPlace(arrayValue);
  console.log(arrayValue);
  // → [5, 4, 3, 2, 1]
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>"use strict";
  var sampleArray = [1,3,5,7,9];
  
  function reverseArrayInPlace (someArray) {
   var MiddleIndex = (Math.floor(someArray.length/2));
   for (var i = 0;  i &lt;= MiddleIndex-1; i++) {
    var currentValue = someArray[i];
    var mirrorIndex = someArray[someArray.length -i -1];
    var temp = currentValue;
    currentValue = mirrorIndex;
    mirrorIndex = temp;
   }
    
   return someArray;
  }
  
  console.log(reverseArrayInPlace(sampleArray));</code></pre>
  </div>
  </div>
  </p>