Skip to content

Instantly share code, notes, and snippets.

@KyleFlemington
Created October 23, 2016 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyleFlemington/d8768a93ff28b68af4712fca4d586393 to your computer and use it in GitHub Desktop.
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.
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