Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andhikamaheva/6dc245d36bb85774527a693233406934 to your computer and use it in GitHub Desktop.
Save andhikamaheva/6dc245d36bb85774527a693233406934 to your computer and use it in GitHub Desktop.
Codility CyclicRotation Exercise Solution (JavaScript/NodeJS)
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A, K) {
// write your code in JavaScript (Node.js 8.9.4)
if (A.length === K || K === 0) {
return A
} else if (A.length === 0) {
return []
}
for (let i = 0; i < K; i++) {
let lastValue = A.pop()
A.unshift(lastValue)
}
return A
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment