Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reverseStringOne(string){
- let reversed = ""; //Where the reversed string will be held
- for(index = string.length-1; index >=0; index--){
- //Starting the loop at the end of the string, ending when the string hits 0, we are decreasing the count
- reversed += string[index];
- //Adding each letter to the reversed string
- }
- return reversed;//Returns the string reversed
- }
- console.log(reverseStringOne("Good Day"));//yaD dooG
- function reverseStringTwo(string){
- //This returns the reversal of a string
- return string
- .split('')// Step [1]
- .reverse()// Step [2]
- .join('');// Step [3]
- //Does it always follow this order, and is this method more 'efficient' to do?
- }
- console.log(reverseStringTwo("Good Night"));//thgiN dooG
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement