1function rotateArray(A, K) {
2 if (!A.length) return A;
3 let index = -1;
4 while (++index < K) {
5 A.unshift(A.pop());
6 }
7 return A;
8}
9
10[
11 rotateArray([3, 8, 9, 7, 6], 3),
12 rotateArray([0, 0, 0], 1),
13 rotateArray([1, 2, 3, 4], 4),
14 rotateArray([], 4),
15].join(' | ');