SOURCE

var arr1 = [3, 1, 5, 6, 1, 8, 6];
var arr2 = [3, 1, 5, 6, 1, 8, 6];
console.log(rotate1(arr1,3));
console.log(rotate2(arr2,3));

function rotate2 (arr, k) {
  var len = arr.length;
  var temp1 = arr.slice(0,len-k);
  var temp2 = arr.slice(len-k,len);
  arr = temp2.concat(temp1);
  return arr;
}

function rotate1 (arr, k) {
  arr = arr.reverse();
  var temp1 = arr.slice(0,k).reverse();
  var temp2 = arr.slice(k,arr.length).reverse();
  arr = temp1.concat(temp2);
  return arr;
}
console 命令行工具 X clear

                    
>
console