title: Cesar decryption. How to deal with non-alphanumerical chars | JS
body: <p>Build a function which takes an encrypted string as argument. it's a Cesar encryption. Like: encrypted character + 5 (or whatever number).</p>
  
  <p><strong>Problem: The encrypted string contains non-alphanumeric chars like " " or "!".</strong></p>
  
  <p>I build a very verbose function which is attached below for completion. <strong>The main part to solve the above mentioned problem is:</strong></p>
  
  <pre><code>  let z = /[^A-^Z]/g;
    if (strIn.search(z) !== 0) {
      let n = strIn.search(z);
      wordArr.splice(n, 0, strIn[n]);
  </code></pre>
  
  <p><code>strIn</code>  is the uppercase version of the input string (the encrypted string)
  <code>wordArr</code> is the decrypted version <strong>without</strong> non alphanumeric chars.</p>
  
  <p>I tried to loop like this:</p>
  
  <pre><code>  for (var i = 0; i &lt; strIn.length; i++) {
      if (strIn.search(z) !== 0) {
        let n = strIn.search(z);
        wordArr.splice(n, 0, strIn[n]);
      }
    }
  </code></pre>
  
  <p>I also tried a while loop. Similar successless. 
  I also tried to map. But than console throws: </p>
  
  <pre><code> strIn.map is not a function
  </code></pre>
  
  <p><strong>Could anyone explain this behavior and give me just a hint how to solve this problem.
  1.) Using a loop 
  2.) Using something better if possible</strong></p>
  
  <p>Here my verbose code for reference or whatever:</p>
  
  <pre><code>function rot13(str) {
    let upper = str.toUpperCase().split("");
    let index = [];
    let decode = [];
  
    const alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
    for (var i = 0; i &lt; upper.length; i++) {
      if (alpha.indexOf(upper[i]) === -1) {
        index.push(upper[i]);
      } else if (alpha.indexOf(upper[i]) !== -1) {
        index.push(alpha.indexOf(upper[i]));
      }
    }
    console.log("index: " + index);
  
    let elem = index.map(function(a, b) {
      if (a === 13) {
        return a - 13;
      } else if (a + 13 &lt;= 26) {
        return a + 13;
      } else if (a + 13 &gt; 26) {
        return a - 13;
      }
    });
  
    console.log("elem :" + elem);
  
    for (var j = 0; j &lt; elem.length; j++) {
      decode.push(alpha[elem[j]]);
    }
    let word = decode.join("");
    let strIn = upper.join("");
  
    console.log("strIn: " + strIn);
  
    let z = /[^A-^Z]/g;
    // let z = /[\!]/g;
  
    let wordArr = Array.from(word);
  
      if (strIn.search(z) !== 0) {
        let n = strIn.search(z);
        wordArr.splice(n, 0, strIn[n]);
      }
  
    console.log("wordArr: " + wordArr);
    console.log(wordArr.join(""));
  
    console.log(strIn.search(z));
  }
  
  rot13("SERR CVMMN!");
  </code></pre>