Okay, so I do not know if the title is right or not, but what I am struggling to do is find an algorithm to do something like this. So we have an input array such as: ['a','b', 'c', 'd', ...] until the end of the alphabet, and a number to shift with. I have to output the array like ['x', 'y', 'z', 'a', 'b', 'c', ...] if I have a number 3 to shift with; Any ideas on how to do it? I tried:
function solve(args)
{
let arr = ['a', 'b', 'c', 'd'];
let number = 3;
for (let i = 0; i < arr.length; i++)
{
if (typeof arr[i + 1] === undefined)
{
arr[0] = arr[i];
}
else if (typeof arr[i - 1] === undefined)
{
arr[arr.length - 1] = arr[0];
}
else
{
arr[i] = arr[i + 1];
}
}
console.log(arr);
}