Peter Stuifzand
39dd45b65d
All checks were successful
continuous-integration/drone/push Build is passing
21 lines
385 B
JavaScript
21 lines
385 B
JavaScript
function reverse(a, from, to) {
|
|
--from;
|
|
while (++from < --to) {
|
|
var tmp = a[from];
|
|
a[from] = a[to];
|
|
a[to] = tmp;
|
|
}
|
|
}
|
|
|
|
function rotate(a, from, to, k) {
|
|
var n = to - from;
|
|
k = (k % n + n) % n;
|
|
if (k > 0) {
|
|
reverse(a, from, from + k);
|
|
reverse(a, from + k, to);
|
|
reverse(a, from, to);
|
|
}
|
|
}
|
|
|
|
export default rotate;
|