Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
simple stack implementation in js
const stack = (() => {
let arr = [],
index = -1;
const obj = {
push(val) {return arr[index += 1] = val},
pop() {
const val = arr[index];
arr[index] = undefined;
if (index >= 0) index -= 1;
return val;
},
isEmpty() {return index < 0}
}
return obj;
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment