wiki/list-editor/util.js
Peter Stuifzand 39dd45b65d
All checks were successful
continuous-integration/drone/push Build is passing
Rotate items to moveBefore
2020-10-30 23:43:00 +01:00

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;