I want to move the first character of a string to the end and then add "ay" to it, I tried to solve it but I couldn't and then I found this solution. can you please explain to me the logic in this code.
function pigIt(str){
str = str.split(' ');
for(let i = 0;i<str.length;i++){
if(/[a-zA-Z]/.test(str[i])){
str[i] = str[i].slice(1) + str[i][0] + 'ay';
}
}
return str.join(' ');
}
console.log(pigIt('Pig latin is cool'));