JSFiddle - React, Tailwind, and code Playground
by hescano
JavaScript
function decipherThis(str) {
function swap(s) {
return s[0] + s[s.length - 1] + s.substring(2, s.length - 1) + s[1];
}
var wLength;
var charCode;
var first;
var word;
return str.split(' ').map((w) => {
charCode = parseInt(w);
wLength = charCode.toString().length;
first = String.fromCharCode(charCode);
if (wLength > w.length) {
return first;
}
word = String.fromCharCode(charCode) + w.replace(charCode, '');
if (word.length > 2) {
return swap(word);
}
return word;
}).join(' ');
}
console.log(decipherThis('72eva 97 103o 97t 116sih 97dn 115ee 104wo 121uo 100o'));