Created
November 30, 2018 10:01
-
-
Save guilhermepontes/22f539c2f99e2d9f1978d6d5feb79c74 to your computer and use it in GitHub Desktop.
stack data structure
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
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