feat: added solution (#34293)
This commit is contained in:
committed by
Christopher McCormack
parent
8d6f59dcce
commit
0c4ab033aa
@ -74,6 +74,28 @@ function Stack() {
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
class Stack {
|
||||||
|
constructor() {
|
||||||
|
this.collection = [];
|
||||||
|
}
|
||||||
|
print(){
|
||||||
|
console.log(this.collection);
|
||||||
|
}
|
||||||
|
push(val){
|
||||||
|
this.collection.push(val);
|
||||||
|
}
|
||||||
|
pop(){
|
||||||
|
return this.collection.pop();
|
||||||
|
}
|
||||||
|
peek(){
|
||||||
|
return this.collection[this.collection.length-1];
|
||||||
|
}
|
||||||
|
isEmpty(){
|
||||||
|
return this.collection.length === 0;
|
||||||
|
}
|
||||||
|
clear(){
|
||||||
|
return this.collection.length = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
Reference in New Issue
Block a user