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());