function solution(A, K) {
let arr = Array.from(A); // clone
let n = K % A.length; // for better performance

for (let i = 0; i < n; i++) {
let val = arr.pop();
arr.unshift(val);
}

return arr;
}

function solution(A, K) {
let arr = [];

for (let i = 0, j; i < A.length; i++) {
j = (i + K) % A.length;
arr[j] = A[i];
}

return arr;
}


'IT General' 카테고리의 다른 글

Codility #3-PermMissingElem  (0) 2018.08.18
Codility #3-FrogJmp  (0) 2018.08.18
Codility #2-OddOccurrencesInArray  (0) 2018.08.18
Fibonacci function without recursion  (0) 2018.08.15
Codility #1-BinaryGap  (0) 2018.08.15

+ Recent posts