Skip to content

Instantly share code, notes, and snippets.

@guilhermepontes
Created November 30, 2018 10:01
Show Gist options
  • Save guilhermepontes/22f539c2f99e2d9f1978d6d5feb79c74 to your computer and use it in GitHub Desktop.
Save guilhermepontes/22f539c2f99e2d9f1978d6d5feb79c74 to your computer and use it in GitHub Desktop.
stack data structure
function createStack() {
const stack = [];
return {
push(item) {
stack.push(item)
},
pop() {
return stack.pop()
},
peek() {
return stack[stack.length - 1]
},
get length() {
return stack.length
},
isEmpty() {
return stack.length === 0
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment