SHARE
TWEET

Untitled

a guest Jun 25th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var str = "i am javascript";
  2. // result "i ma tpircsavaj"
  3. function reverseString(myStr){
  4.     var strlen = myStr.length, result = "", reverseStr = "", reverseStrArr = [];
  5.   for(var i = strlen-1; i >= 0; i--){
  6.     reverseStr +=  myStr[i];
  7.   }
  8.  
  9.     for(var j = 0; j < strlen; j++){
  10.     if(reverseStr[j] == " "){
  11.       reverseStrArr.push(result);
  12.       result = "";
  13.     }else{
  14.       result += reverseStr[j];
  15.       if(j + 1 == strlen){
  16.         reverseStrArr.push(result);
  17.         result = "";
  18.       }
  19.     }
  20.   }
  21.  
  22.   for(var k=reverseStrArr.length - 1; k >= 0; k--){
  23.     result += reverseStrArr[k] + " "
  24.   }
  25.   console.log(result);
  26. }
  27. reverseString(str);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top