react-use-stack
Version:
``` Stack data structure as npm package This package helps you to simulate the behaviour of a stack. If you are familiar with c++ stacks this has exactly same methods. ```
29 lines (23 loc) • 483 B
JavaScript
let stack = [];
module.exports.push = function(x){
stack.push(x);
}
module.exports.pop = function(){
if(stack.length === 0){
return -1;
}
stack.pop();
return 1;
}
module.exports.top = function(){
if(stack.length === 0){
return "empty";
}
return stack[stack.length-1];
}
module.exports.isEmpty = function(){
return stack.length === 0;
}
module.exports.size = function(){
return stack.length;
}