Skip to content

Commit 098d527

Browse files
Merge pull request Nivedita-coder#59 from quanKM/add_stack
Add stack structure
2 parents 5d896b6 + 0ffa946 commit 098d527

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎Javascript_Algo/stack.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function Stack() {
2+
const stack = []
3+
4+
return {
5+
push(item) {
6+
return stack.push(item)
7+
},
8+
9+
pop() {
10+
return stack.pop()
11+
},
12+
13+
peek() {
14+
return stack[this.length - 1]
15+
},
16+
17+
get length() {
18+
return stack.length
19+
},
20+
21+
isEmpty() {
22+
return this.length === 0
23+
},
24+
}
25+
}

0 commit comments

Comments
 (0)