Created
October 23, 2016 03:10
-
-
Save KyleFlemington/d8768a93ff28b68af4712fca4d586393 to your computer and use it in GitHub Desktop.
Reversing a string without using Array.prototype.reverse or Array.prototype.join functions to solve this problem.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var toBeReversed = process.argv[2]; | |
function reverse(toBeReversed) { | |
var revOutput = ""; | |
for (var i = toBeReversed.length -1; i >= 0; i--) { | |
revOutput += toBeReversed[i]; | |
} | |
return revOutput; | |
} | |
console.log(reverse(toBeReversed)); | |
// 5. A standard for loop where i equals one less than the original length; i has to be greater or equal than 0 ; i decreases incrementally | |
// 6. Empty array 'revOutput' gets input starting at the last character of the string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment