Shifting rows and columns in 2D arrays - Javascript
<p>I have a situation as such:</p>

<pre><code>var array = [
  [1,2,3],
  [4,5,6],
  [7,8,9]
]
</code></pre>

<p>And I am trying to create a function that shifts either a row or a column so the result would be:</p>

<pre><code>shiftRow(array, 1) 

[
  [3,1,2],
  [4,5,6],
  [7,8,9]
]

shiftColumn(array,1)

[
  [7,2,3],
  [1,5,6],
  [4,8,9]
]
</code></pre>

<p>I want the first number to be the last number then continue from there in any instance. I have tried several nested for loops, and I'm quite stuck at figuring this out. Keep in mind I have only been coding for a few months though. </p>

<p>This is what I have so far. It gives me an <code>undefined</code> error at the end and it is moving it the wrong way.</p>

<pre><code>function shiftRow(arr) {
  var temp = arr
  for(var i = 0; i &lt; temp.length; i++) {
    for(var j = 0; j &lt; temp[i].length; j++) {
      temp[i][j] = temp[i][j+1]
    }
  }
  return temp;
}
</code></pre>