title: Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a multidimensional array
body: <p>I am working through a javascript problem that asks me to:</p>
  
  <p>Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a multidimensional array.</p>
  
  <p>For example, the input</p>
  
  <pre><code>chunk([0, 1, 2, 3, 4, 5], 2)
  </code></pre>
  
  <p>should return the 'chunked arrays':
  [[0, 1], [2, 3], [4, 5]]</p>
  
  <p>I can get it to work for most examples but when there are more than 2 chunks it switches the order and I am not sure why. Here is the code that I have written:</p>
  
  <pre><code>function chunk(arr, size) {
    var newArray = [],
        i, temp = arr;
    for (i = 0;i&lt;= arr.length-size;i+=size){
      newArray.push(arr.slice(i,i+size));
      temp.splice(i,size);
    }
    newArray.push(temp);
    return newArray;
  }
  chunk(['a', 'b', 'c', 'd'], 2);
  </code></pre>