Last active
September 7, 2018 15:21
-
-
Save frentsel/8c664f052bad8ec236386cfd672f206f to your computer and use it in GitHub Desktop.
Data structure - Stack (javascript)
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
const Stack = new function() { | |
let data = []; | |
this.pop = () => data.pop(); | |
this.push = (el) => data.push(el); | |
this.peek = () => data[data.length - 1]; | |
}; | |
Stack.push(1); | |
Stack.push(2); | |
console.log(Stack.peek()); // [1, 2] | |
Stack.pop(); | |
console.log(Stack.peek()); // [1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment