Skip to content

Instantly share code, notes, and snippets.

@frentsel
Last active September 7, 2018 15:21
Show Gist options
  • Save frentsel/8c664f052bad8ec236386cfd672f206f to your computer and use it in GitHub Desktop.
Save frentsel/8c664f052bad8ec236386cfd672f206f to your computer and use it in GitHub Desktop.
Data structure - Stack (javascript)
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