Skip to content

Commit b119835

Browse files
committed
feat(L-I): Readme
1 parent 85e7262 commit b119835

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

L-I/0003 Stack ( L-I )/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# 0003 Stack ( L-I )
2+
3+
## Problem
4+
5+
Create a class that has 3 method and 1 property.
6+
7+
- Push method add new element to the stack
8+
- Pop method remove last added element and return removed element
9+
- Peek return last added element
10+
- Size property return stack size
11+
12+
## Solution
13+
14+
```javascript
15+
class Stack {
16+
constructor() {
17+
this.stack = []
18+
}
19+
20+
push(value) {
21+
this.stack.push(value)
22+
}
23+
24+
pop() {
25+
return this.stack.pop()
26+
}
27+
28+
peek() {
29+
return this.stack.at(-1)
30+
}
31+
32+
get size() {
33+
return this.stack.length
34+
}
35+
}
36+
```
37+
38+
## References
39+
40+
- [Class MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes)
41+
- [Stack GeeksForGeeks](https://www.geeksforgeeks.org/implementation-stack-javascript/)
42+
- [Array MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
43+
44+
## Problem Added By
45+
46+
- [GitHub](https://www.github.com/kennarddh)
47+
48+
## Contributing
49+
50+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
51+
52+
Please make sure to update tests as appropriate.

0 commit comments

Comments
 (0)