Skip to content

Instantly share code, notes, and snippets.

@perjansson
Created January 2, 2018 19:40
Show Gist options
  • Save perjansson/9bd9853594cac155a899a6b29c97cd02 to your computer and use it in GitHub Desktop.
Save perjansson/9bd9853594cac155a899a6b29c97cd02 to your computer and use it in GitHub Desktop.
reverse a string using a stack
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