UNPKG
js-dsa-utils
Version:
latest (1.3.0)
1.3.0
1.2.0
1.1.0
1.0.0
Basic DSA utilities (sorting, searching, stack, queue,linked list etc.)
js-dsa-utils
/
src
/
stack.js
20 lines
(18 loc)
•
309 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class
Stack
{
constructor
() {
this
.stack = []; } push(
val
) {
this
.stack.push(
val
); } pop() {
return
this
.stack.pop(); } peek() {
return
this
.stack[
this
.stack.length -
1
]; } isEmpty() {
return
this
.stack.length ===
0
; } } module.exports = { Stack };