I'm making a deciphering function and I'm stuck on a part where I need to swap the positions of the second letter and the last letter of the string. I have also tried using the replace method but I think substring should be used.
Hello should equal Holle, etc
function decipher(str) {
let s = ""
for (let word of str.split(" ")){
let dig = word.match(/\d+/)[0]
word = word.replace(dig, String.fromCharCode(dig))
let secondLetter = word[1]
let lastLetter = word[word.length - 1]
let swapped = word.substring(0,1) + lastLetter + word.substring(2,3) + secondLetter
s += swapped + " "
}
return s
};