wiki/list-editor/util.js

21 lines
385 B
JavaScript
Raw Normal View History

2020-10-30 22:43:00 +00:00
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;