Last active
December 4, 2018 22:00
-
-
Save joelbarbosa/a2737ac6954eb6528c409431cc7b499d 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 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()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment