Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Add comments in Stack.js file #1309

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions algorithms/JavaScript/src/stacks/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ class Stack {
this.items = [];
}

//creating push method
push(element) {
this.items.push(element);
}

//creating pop method
pop() {
return this.items.pop();
}

//creating printStack method
printStack() {
console.log(this.items);
}
}

//creating Stack object
const stack = new Stack();
stack.push(1);
stack.push(2);
Expand Down
30 changes: 30 additions & 0 deletions algorithms/JavaScript/src/stacks/stacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Stack {
constructor() {
this.items = [];
}

push(element) {
this.items.push(element);
}

pop() {
return this.items.pop();
}

printStack() {
console.log(this.items);
}
}

const stack = new Stack();
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);

stack.printStack();

console.log(stack.pop());

stack.printStack();