Advertisement
EntropyStarRover

Untitled

Oct 23rd, 2019
157
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.     let inp = document.getElementById("array").value;
  4.     let resultDiv = document.getElementById("result");
  5.  
  6.  
  7.     let splitPoint = inp.indexOf(", ")-1 ;
  8.     let keyWord = inp.substring(2, splitPoint);
  9.     let msg = inp.substring(splitPoint + 5, inp.length - 2)
  10.  
  11.     let messagepatt = new RegExp(`${keyWord}(\\s)+([A-Z!%\\$#]){8,}(\\s|\\.|,$)+`, "gmi");
  12.  
  13.     while ((result = messagepatt.exec(msg)) !== null) {
  14.         let tp = result[0].split(" ");
  15.      
  16.         if (tp[1] === tp[1].toUpperCase()) {
  17.                 let wordToDecode = tp[1];
  18.  
  19.             while (tp[1].includes("!")) {
  20.                 tp[1] = tp[1].replace("!", "1")
  21.             }
  22.  
  23.             while (tp[1].includes("%")) {
  24.                 tp[1] = tp[1].replace("%", "2")
  25.             }
  26.             while (tp[1].includes("#")) {
  27.                 tp[1] = tp[1].replace("#", "3")
  28.             }
  29.             while (tp[1].includes("$")) {
  30.                 tp[1] = tp[1].replace("$", "4")
  31.             }
  32.  
  33.               msg = msg.replace(wordToDecode, tp[1].toLowerCase())
  34.         }
  35.     }
  36.  
  37.  
  38.     let separators = /(\.|\?)\s/gm;
  39.     let arr = msg.split(separators);
  40.     let ps=[];
  41.  
  42.     for (let i = 0; i < arr.length; i += 2) {
  43.         let newP = document.createElement("p");
  44.          let phrase=arr[i] + arr[i + 1];
  45.         if (phrase!==undefined)
  46.                ps.push(phrase);
  47.  
  48.     }
  49.  
  50. ps.forEach(p=>{
  51.     let np=document.createElement("p");
  52.     np.textContent=p;
  53.     resultDiv.appendChild(np)
  54. })
  55.  
  56. console.log(resultDiv.children[0].textContent)
  57. console.log(resultDiv.children[1].textContent)
  58. console.log(resultDiv.children[2].textContent)
  59.  
  60. }
Advertisement
RAW Paste Data Copied
Advertisement