Skip to content

Instantly share code, notes, and snippets.

@peterschmiz
Last active April 24, 2016 06:46
Show Gist options
  • Save peterschmiz/1623dbd7ac0d3b4faead161f5a90e097 to your computer and use it in GitHub Desktop.
Save peterschmiz/1623dbd7ac0d3b4faead161f5a90e097 to your computer and use it in GitHub Desktop.
function solution(A, K) {
var result = [],
i = 0,
j = 0;
if (A.length === 0) {
return A;
}
if (K > A.length) {
K = K % A.length;
}
for(i; i < K; i++){
result[i] = A[A.length - K + i];
}
for(i = K; i < A.length; i++){
result[i] = A[j];
j++;
}
A = result.slice();
return A;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment