Answer the question
In order to leave comments, you need to log in
How can I solve this problem using Javascript?
Please tell me the following.
There is a key: 18 and an encrypted message: What is the best way to decrypt it?
Only one way came to my mind.
Are there options to solve this with es6?
Answer the question
In order to leave comments, you need to log in
It seems that the author wants to see how the function can be rewritten in a more functional style. For example, like this:
function convertText(str, key) {
key = (26 - key) % 26;
return [...str].map(symb => {
const code = symb.charCodeAt(0);
let shift = 0;
if ((65 <= code) && (code <= 90)) {
shift = 65;
} else if ((97 <= code) && (code <= 122)) {
shift = 97;
}
if (shift > 0) {
return String.fromCharCode(shift + ((code - shift + key) % 26));
} else {
return symb;
}
}).join('');
}
alert(convertText('Hmjw uzsfuw dwv eq xjawfv Zwjumdw Hgajgl, xgjewjdq uzawx gx lzw Twdyasf xgjuw, lg tw ugffwulwv oalz lzw Klqdwk uskw', 18));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question