Skip to content

Instantly share code, notes, and snippets.

@joelbarbosa
Last active December 4, 2018 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelbarbosa/a2737ac6954eb6528c409431cc7b499d to your computer and use it in GitHub Desktop.
Save joelbarbosa/a2737ac6954eb6528c409431cc7b499d to your computer and use it in GitHub Desktop.
function createStack() {
const array = [];
return {
push(item) {
array.push(item);
},
pop() {
return array.pop();
},
get length() {
return array.length;
},
peek() {
return array[array.length -1];
}
}
}
const stack = createStack();
stack.push(1);
stack.push(20);
stack.push('hello');
console.log(stack.length)
console.log(stack.peek());
stack.pop();
console.log(stack.peek());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment