Created
May 4, 2017 18:11
-
-
Save wdiasvargas/702c4cde78e496f87a4df85f30f261bc to your computer and use it in GitHub Desktop.
assim tbm funciona ta com arrow functions mas ainda nao ta modular :/
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
/** | |
* Write by wdiasvargas on 04/05/17. | |
* www.williamdiasvargas.com.br | |
* | |
**/ | |
'use strict' | |
//STACK com ES6 | |
class Stack { | |
constructor () { | |
this.data = []; | |
this.push = (element) => this.data.push(element); | |
this.pop = () => this.data.pop() || -1; | |
this.peek = () => this.data[this.data.length -1] || -1; | |
this.isEmpty = () => this.data.length == 0; | |
this.clear = () => this.data = []; | |
this.size = () => this.data.length; | |
this.print = () => console.log(this.data.toString()); | |
} | |
} | |
let stack = new Stack(); | |
console.log(stack.push(1)) | |
console.log(stack.push(3)) | |
console.log(stack.push(5)) | |
console.log(stack.print()) | |
console.log(stack.pop()) | |
console.log(stack.print()) | |
// isEmpty.es6 export default () => this.data.length == 0; | |
// size.es6 export default () => this.data.length; | |
// push.es6 export default (element) => this.data.push(element) | |
// pop.es6 export default () => this.data.pop() || -1; | |
// peek.es6 export default () => this.data[this.data.length -1] || -1; | |
// clear.es6 export default() => this.data = []; | |
// print.es6 export default () => console.log(this.data.toString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment