javascript increment numerical array
<p>We have a numerical array with arbitrary max values for each element. How do we increment the elements so the array would go from <code>[0, 0, 0]</code> to <code>[x, y, z]</code>? </p>

<p>To illustrate if the max array is <code>[2, 1, 2]</code> and we start the main array at <code>[0, 0, 0]</code> incrementing should take the main array through these steps:</p>

<pre><code>[0, 0, 0]
[1, 0, 0]
[2, 0, 0]
[0, 1, 0]
[1, 1, 0]
[2, 1, 0]
[0, 0, 1]
[1, 0, 1]
[2, 0, 1]
[0, 1, 1]
[1, 1, 1]
[2, 1, 1]
[0, 0, 2]
[1, 0, 2]
[2, 0, 2]
[0, 1, 2]
[1, 1, 2]
[2, 1, 2]
</code></pre>

<p>I have written a function which stops incrementing as soon as it reaches a max of 1. Here is my code:</p>

<pre><code>var maxes = [2, 1, 2];
var myArray = [0, 0, 0];

function step() {
  for(var i = 0; i &lt; myArray.length; i++) {
    if(myArray[i] == maxes[i]) {
       continue;
    } else {
       myArray[i] = myArray[i] + 1;
       return;
    }
  }
  return false;
}

for(j = 0; j &lt; 100; j++) {
  result = step();
  if(!result) break;
  console.log(result);
}
</code></pre>
