Created
January 2, 2018 19:40
-
-
Save perjansson/9bd9853594cac155a899a6b29c97cd02 to your computer and use it in GitHub Desktop.
reverse a string using a stack
This file contains hidden or 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
| const reverseString = input => { | |
| const stack = [] | |
| for (let s of input) { | |
| stack.push(s) | |
| } | |
| let output = "" | |
| while (stack.length > 0) { | |
| output += stack.pop() | |
| } | |
| return output | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment