Last active
February 9, 2019 20:03
-
-
Save Damimd10/8599a38140d1b4be90e883033208ed1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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