title: Javascript-Given an array, swap first and last, third and third-to-last, etc
body: <p>The idea is to have the following input/output:</p>
  
  <ul>
  <li>input would be ['true',42,'Ada',2,'pizza'] and output would be ['pizza',42,'Ada',2,'true'];</li>
  <li>for input [1,2,3,4,5,6], output would be [6,2,4,3,5,1]</li>
  </ul>
  
  <p>Here is the code I currently have:</p>
  
  <pre><code>function swapTowardsTheCenter(array) {
  
  var len = array.length;
  var idx = 0;
  var lastIdx = array.length -1;
  
  while (idx&lt;=len/2 &amp;&amp; lastIdx&gt;=len/2) {
      var temp = array[idx];
      array[idx] = array[lastIdx];
      array[lastIdx] = temp;
      idx = idx + 2;
      lastIdx = lastIdx - 2;
  
  }
  
  return array;
  
  }
  </code></pre>
  
  <p>Could anyone please help me find my mistake? Thank you!</p>