Skip to content

Instantly share code, notes, and snippets.

@Damimd10
Last active February 9, 2019 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Damimd10/8599a38140d1b4be90e883033208ed1e to your computer and use it in GitHub Desktop.
Save Damimd10/8599a38140d1b4be90e883033208ed1e to your computer and use it in GitHub Desktop.
function createStack() {
const stack = []
return {
push(item) {
stack.push(item)
},
pop() {
return stack.pop()
},
peek() {
return stack[stack.length - 1]
},
get length() {
return stack.length
},
isEmpty() {
return stack.length == 0
}
}
}
const lowerBodyStack = createStack();
lowerBodyStack.push('underwear')
lowerBodyStack.push('socks')
lowerBodyStack.push('pants')
lowerBodyStack.push('shoes')
lowerBodyStack.pop()
lowerBodyStack.peek() // pants
lowerBodyStack.length() // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment