Skip to content

Instantly share code, notes, and snippets.

@desigens
Created June 30, 2018 11:22
Show Gist options
  • Save desigens/6022e6919d41c84f10665db4a635d495 to your computer and use it in GitHub Desktop.
Save desigens/6022e6919d41c84f10665db4a635d495 to your computer and use it in GitHub Desktop.
Codility CyclicRotation
# 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