title: Using temporary variables in a for loop
body: <p>I am writing a function that shuffles the item in an array:</p>
  
  <pre><code>this.shuffle = function () {
      ...
  </code></pre>
  
  <p>First, I get the two halves of the array and set up a third empty array:</p>
  
  <pre><code>    this.leftHalf = this.cards.slice(0, this.size() / 2);
      this.rightHalf = this.cards.slice(this.size() / 2);
      this.result = [];
  </code></pre>
  
  <p>Next, I put one card from each half into the result array:</p>
  
  <pre><code>    for (var i = ...) {
          this.result.unshift(this.leftHalf[i]);
          this.result.unshift(this.rightHalf[i]);
      }
  </code></pre>
  
  <p>Last, I assign the result array to my original array and delete the "temporary" variables:</p>
  
  <pre><code>    this.cards = this.result;
  
      delete this.leftHalf;
      delete this.rightHalf;
      delete this.result;
  }
  </code></pre>
  
  <p>My question: Is this a sensible way to approach this problem, or is there a better way that doesn't involve setting up temporary variables? I thought about using private variables instead (but wasn't sure if it would be any better performance wise) like so:</p>
  
  <pre><code>var leftHalf, rightHalf, result;
  
  this.shuffle = function () {
      leftHalf = ...
  </code></pre>
  
  <p>Just curious if there was anything obvious I'm doing wrong or if there's a best practice in these cases.</p>