Created
June 30, 2018 11:22
-
-
Save desigens/6022e6919d41c84f10665db4a635d495 to your computer and use it in GitHub Desktop.
Codility CyclicRotation
This file contains hidden or 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
# https://app.codility.com/programmers/lessons/2-arrays/cyclic_rotation/ | |
function solution(array, times) { | |
let result = [...array]; | |
let length = result.length; | |
times = times % length; | |
for (let i = 0; i < times; i++) { | |
result = [ | |
result[length - 1], | |
...result.slice(0, -1), | |
] | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment