Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* As input will receive an HTML document as a single string. You need to get the text from all the <p> tags and
- * replace all characters which are not small letters and numbers with a space ' '. After that you must decrypt
- * the text - all letters from a to m are converted to letters from n to z accordingly (a -> n, b -> o, ... m -> z).
- * The letters from n to z are converted to letters from a to m accordingly (n -> a, o -> b, ... z -> m).
- * All multiple spaces should then be replaced by only one space!
- * Print at a single line the decrypted text.*/
- "use strict";
- function solve(args) {
- var pattern = /<p>(.*?)<\/p>/g;
- var matchedText;
- var convertedText = '';
- while (matchedText = pattern.exec(args[0])) {
- var decrypted = matchedText[1].split('');
- for (var i = 0; i < decrypted.length; i += 1) {
- var char = decrypted[i];
- if (isFinite(char) || char != char.toUpperCase()) {
- var asciiCode = char.charCodeAt(0);
- if (asciiCode > 96 && asciiCode < 123) {
- asciiCode += (asciiCode < 110) ? 13 : -13;
- decrypted[i] = String.fromCharCode(asciiCode);
- }
- } else {
- decrypted[i] = ' ';
- }
- }
- convertedText += decrypted.join('').replace(/\s+/g, ' ');
- }
- console.log(convertedText);
- }
- solve(['<html><head><title></title></head><body><h1>hello</h1><p>znahny!@#%&&&&****</p><div><button>dsad</button></div><p>grkg^^^^%%%)))([]12</p></body></html>']);
- solve(['<html><head><title></title></head><body><h1>Intro</h1><ul><li>Item01</li><li>Item02</li><li>Item03</li></ul><p>jura qevivat va jrg fyvccrel fabjl</p><div><button>Click me, baby!</button></div><p> pbaqvgvbaf fabj punvaf ner nofbyhgryl rffragvny sbe fnsr unaqyvat nygubhtu fabj punvaf znl ybbx </p><span>This manual is false, do not trust it! The illuminati wrote it down to trick you!</span><p>vagvzvqngvat gur onfvp vqrn vf ernyyl fvzcyr svg gurz bire lbhe gverf qevir sbejneq fybjyl naq gvtugra gurz hc va pbyq jrg</p><p> pbaqvgvbaf guvf vf rnfvre fnvq guna qbar ohg vs lbh chg ba lbhe gverf </p><div>It is frustrating that you have not put car chains yet... Embarrassing...</div><p>orsber lbh ernpu fabjl ebnqf lbh jvyy znxr lbhe yvsr jnl rnfvre</p></body>']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement