Skip to content

Commit 554a002

Browse files
committed
remove unnecessary functions
1 parent 0144e77 commit 554a002

File tree

3 files changed

+214
-220
lines changed

3 files changed

+214
-220
lines changed

Data-Structures/Array/Reverse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const Reverse = (arr) => {
99
// limit specifies the amount of Reverse actions
1010
for (let i = 0, j = arr.length - 1; i < arr.length / 2; i++, j--)
11-
[arr[i], arr[j]] = [arr[j], arr[i]] // Swapping elements ES6 way
11+
[arr[i], arr[j]] = [arr[j], arr[i]]
1212

1313
return arr
1414
}

Data-Structures/Stack/Stack.js

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,48 @@
88
// Functions: push, pop, peek, view, length
99

1010
// Creates a stack constructor
11-
const Stack = (function () {
12-
class Stack {
13-
constructor() {
14-
// The top of the Stack
15-
this.top = 0
16-
// The array representation of the stack
17-
this.stack = []
18-
}
19-
20-
// Adds a value onto the end of the stack
21-
push(value) {
22-
this.stack[this.top] = value
23-
this.top++
24-
}
11+
class Stack {
12+
constructor() {
13+
// The top of the Stack
14+
this.top = 0
15+
// The array representation of the stack
16+
this.stack = []
17+
}
2518

26-
// Removes and returns the value at the end of the stack
27-
pop() {
28-
if (this.top === 0) {
29-
return 'Stack is Empty'
30-
}
19+
// Adds a value onto the end of the stack
20+
push(value) {
21+
this.stack[this.top] = value
22+
this.top++
23+
}
3124

32-
this.top--
33-
const result = this.stack[this.top]
34-
this.stack = this.stack.splice(0, this.top)
35-
return result
25+
// Removes and returns the value at the end of the stack
26+
pop() {
27+
if (this.top === 0) {
28+
return 'Stack is Empty'
3629
}
3730

38-
// Returns the size of the stack
39-
size() {
40-
return this.top
41-
}
31+
this.top--
32+
const result = this.stack[this.top]
33+
this.stack = this.stack.splice(0, this.top)
34+
return result
35+
}
4236

43-
// Returns the value at the end of the stack
44-
peek() {
45-
return this.stack[this.top - 1]
46-
}
37+
// Returns the size of the stack
38+
size() {
39+
return this.top
40+
}
4741

48-
// To see all the elements in the stack
49-
view(output = (value) => console.log(value)) {
50-
for (let i = 0; i < this.top; i++) {
51-
output(this.stack[i])
52-
}
53-
}
42+
// Returns the value at the end of the stack
43+
peek() {
44+
return this.stack[this.top - 1]
5445
}
5546

56-
return Stack
57-
})()
47+
// To see all the elements in the stack
48+
view(output = (value) => console.log(value)) {
49+
for (let i = 0; i < this.top; i++) {
50+
output(this.stack[i])
51+
}
52+
}
53+
}
5854

5955
export { Stack }

0 commit comments

Comments
 (0)