title: JS: Reversing a string using nested loop does not work
body: <p>I have written a function called <code>reverseStr</code> that takes in a string as a parameter and returns the string but with the characters in reverse.</p>
  
  <p>For example: <code>reverseStr('bootcamp');</code> => <code>'pmactoob'</code></p>
  
  <p>Following is my program:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function reverseStr(str)
  {
   var splitStr = str.split("");
   console.log(splitStr);
   var reverseString = [];
   for(var i = 0; i &lt;= splitStr.length -1 ; i++)
   {
    for(var j = splitStr.length - 1; j &gt;= 0; j--)
    {
     reverseString[i] = splitStr[j]
    }
   }
  
   return reverseString.toString().replace(/[&amp;\/\\#,+()$~%.'":*?&lt;&gt;{}]/g, '');
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>If I run the function <code>reverseStr("bootcamp")</code> it returns <code>bbbbbbbb</code>.
  Does anyone see a problem with the code? </p>
  
  <p>Note: I DONOT WANT TO USE <code>REVERSE()</code> BUILT-IN FUNCTION </p>
  
  <p>However, I found success with the following code <strong>but still need an answer to my initial question</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function reverseStr(str)
  {
   var splitStr = str.split("");
   reverseStr = "";
   for(var i = splitStr.length - 1; i &gt;= 0 ; i = i - 1)
   {
    reverseStr += splitStr[i];
   }
  
   return reverseStr;
  }</code></pre>
  </div>
  </div>
  </p>