Created
July 2, 2018 06:42
-
-
Save andhikamaheva/6dc245d36bb85774527a693233406934 to your computer and use it in GitHub Desktop.
Codility CyclicRotation Exercise Solution (JavaScript/NodeJS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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