// Array is [1, 2, 3, 4, 5] and x = 2
// final output would be [3, 4, 5, 1, 2]
function moveElementsToEndOfArray(arr, x) {
x = x % (arr.length);
// After this loop array will
// be [1, 2, 3, 4, 5, 1, 2]
for (let i = 0; i < x; i++) {
arr.push(arr[i]);
}
// Splice method will remove first
// x = 2 elements from the array
// so array will be [3, 4, 5, 1, 2]
arr.splice(0, x);
console.log(arr);
}
let arr = [1, 2, 3, 4, 5];
let k = 2;
moveElementsToEndOfArray(arr, k);