Skip to content

Instantly share code, notes, and snippets.

@romaintailhurat
Last active November 8, 2017 09:01
Show Gist options
  • Save romaintailhurat/78d24c702ca3de47ebf53235546ec23f to your computer and use it in GitHub Desktop.
Save romaintailhurat/78d24c702ca3de47ebf53235546ec23f to your computer and use it in GitHub Desktop.
stack created by romaintailhurat - https://repl.it/Mgsq/2
/*
Stack, array implementation
http://www.cs.usfca.edu/~galles/visualization/StackArray.html
*/
class Stack {
constructor() {
this._stack = [];
this._index = -1;
}
push(value) {
this._index++;
this._stack[this._index] = value;
}
pop() {
const resultingArray = this._stack.splice(this._index, 1);
this._index--;
return resultingArray[0];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment