@sachin.talekar07/stack
Version:
A stack data structure implementation with various methods.
29 lines (20 loc) • 432 B
JavaScript
const Stack = () => {
const items = []
const isEmpty = () => items.length === 0
const peek = () => isEmpty() ? null : items[items.length - 1]
const push = item => items.push(item)
const pop = () => isEmpty() ? null : items.pop()
const size = () => items.length
const clear = () => {
items.length = 0
}
return {
peek,
push,
pop,
size,
clear,
isEmpty
}
}
module.exports = Stack