Skip to content

Commit 6fe21d2

Browse files
authored
chore: convert functions to an ES2015 classes (#1656)
* chore: convert functions to an ES2015 classes * remove unnecessary functions
1 parent 314144f commit 6fe21d2

File tree

8 files changed

+384
-378
lines changed

8 files changed

+384
-378
lines changed

Diff for: Conversions/RailwayTimeConversion.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const RailwayTimeConversion = (timeString) => {
2424
const [hour, minute, secondWithShift] = timeString.split(':')
2525
// split second and shift value.
2626
const [second, shift] = [
27-
secondWithShift.substr(0, 2),
28-
secondWithShift.substr(2)
27+
secondWithShift.substring(0, 2),
28+
secondWithShift.substring(2)
2929
]
3030
// convert shifted time to not-shift time(Railway time) by using the above explanation.
3131
if (shift === 'PM') {

Diff for: Data-Structures/Array/Reverse.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
const Reverse = (arr) => {
99
// limit specifies the amount of Reverse actions
10-
for (let i = 0, j = arr.length - 1; i < arr.length / 2; i++, j--) {
11-
const temp = arr[i]
12-
arr[i] = arr[j]
13-
arr[j] = temp
14-
}
10+
for (let i = 0, j = arr.length - 1; i < arr.length / 2; i++, j--)
11+
[arr[i], arr[j]] = [arr[j], arr[i]]
12+
1513
return arr
1614
}
1715
export { Reverse }

Diff for: Data-Structures/Stack/Stack.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
// Functions: push, pop, peek, view, length
99

1010
// Creates a stack constructor
11-
const Stack = (function () {
12-
function Stack() {
11+
class Stack {
12+
constructor() {
1313
// The top of the Stack
1414
this.top = 0
1515
// The array representation of the stack
1616
this.stack = []
1717
}
1818

1919
// Adds a value onto the end of the stack
20-
Stack.prototype.push = function (value) {
20+
push(value) {
2121
this.stack[this.top] = value
2222
this.top++
2323
}
2424

2525
// Removes and returns the value at the end of the stack
26-
Stack.prototype.pop = function () {
26+
pop() {
2727
if (this.top === 0) {
2828
return 'Stack is Empty'
2929
}
@@ -35,23 +35,21 @@ const Stack = (function () {
3535
}
3636

3737
// Returns the size of the stack
38-
Stack.prototype.size = function () {
38+
size() {
3939
return this.top
4040
}
4141

4242
// Returns the value at the end of the stack
43-
Stack.prototype.peek = function () {
43+
peek() {
4444
return this.stack[this.top - 1]
4545
}
4646

4747
// To see all the elements in the stack
48-
Stack.prototype.view = function (output = (value) => console.log(value)) {
48+
view(output = (value) => console.log(value)) {
4949
for (let i = 0; i < this.top; i++) {
5050
output(this.stack[i])
5151
}
5252
}
53-
54-
return Stack
55-
})()
53+
}
5654

5755
export { Stack }

0 commit comments

Comments
 (0)