We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e47f27e commit 3ac97ecCopy full SHA for 3ac97ec
chapter03/01-Stack3.js
@@ -0,0 +1,54 @@
1
+let Stack3 = (function () {
2
+
3
+ const items = new WeakMap();
4
5
+ class Stack3 {
6
7
+ constructor () {
8
+ items.set(this, []);
9
+ }
10
11
+ push(element){
12
+ let s = items.get(this);
13
+ s.push(element);
14
+ items.set(this, s);
15
+ };
16
17
+ pop(){
18
19
+ let r = s.pop();
20
21
+ return r;
22
23
24
+ peek(){
25
26
+ return s[s.length-1];
27
28
29
+ isEmpty(){
30
+ return items.get(this).length == 0;
31
32
33
+ size(){
34
35
+ return s.length;
36
37
38
+ clear(){
39
40
41
42
+ print(){
43
44
+ console.log(this.toString());
45
46
47
+ toString(){
48
+ return items.get(this).toString();
49
50
51
52
+ return Stack3;
53
+})();
54
0 commit comments