Advertisement
Guest User

FuzzyBear Random Question 1

a guest
May 8th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  function reverseStringOne(string){
  3.     let reversed = ""; //Where the reversed string will be held
  4.     for(index = string.length-1; index >=0; index--){
  5.         //Starting the loop at the end of the string, ending when the string hits 0, we are decreasing the count
  6.          reversed += string[index];
  7.          //Adding each letter to the reversed string
  8.      }
  9.      return reversed;//Returns the string reversed
  10.  }
  11. console.log(reverseStringOne("Good Day"));//yaD dooG
  12.  
  13.  
  14. function reverseStringTwo(string){
  15.     //This returns the reversal of a string
  16.     return string
  17.             .split('')// Step [1]
  18.             .reverse()// Step [2]
  19.             .join('');// Step [3]
  20.              //Does it always follow this order, and is this method more 'efficient' to do?
  21. }
  22. console.log(reverseStringTwo("Good Night"));//thgiN dooG
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement