/ Published in: JavaScript
Take the first item in an array an place it last or the last item and place it first.
Expand |
Embed | Plain Text
function shiftRight(arr) { var temp = new Array(); temp.push(arr[arr.length-1]); for (i = 0; i <= arr.length-2; i++) temp.push(arr[i]); return temp; } function shiftLeft(arr) { var temp = new Array(); for (i = 1; i <= arr.length-1; i++) temp.push(arr[i]); temp.push(arr[0]); return temp; }
You need to login to post a comment.
