Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Conversions/RailwayTimeConversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const RailwayTimeConversion = (timeString) => {
const [hour, minute, secondWithShift] = timeString.split(':')
// split second and shift value.
const [second, shift] = [
secondWithShift.substr(0, 2),
secondWithShift.substr(2)
secondWithShift.substring(0, 2),
secondWithShift.substring(2)
]
// convert shifted time to not-shift time(Railway time) by using the above explanation.
if (shift === 'PM') {
Expand Down
8 changes: 3 additions & 5 deletions Data-Structures/Array/Reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

const Reverse = (arr) => {
// limit specifies the amount of Reverse actions
for (let i = 0, j = arr.length - 1; i < arr.length / 2; i++, j--) {
const temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
}
for (let i = 0, j = arr.length - 1; i < arr.length / 2; i++, j--)
[arr[i], arr[j]] = [arr[j], arr[i]]

return arr
}
export { Reverse }
18 changes: 8 additions & 10 deletions Data-Structures/Stack/Stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
// Functions: push, pop, peek, view, length

// Creates a stack constructor
const Stack = (function () {
function Stack() {
class Stack {
constructor() {
// The top of the Stack
this.top = 0
// The array representation of the stack
this.stack = []
}

// Adds a value onto the end of the stack
Stack.prototype.push = function (value) {
push(value) {
this.stack[this.top] = value
this.top++
}

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

// Returns the size of the stack
Stack.prototype.size = function () {
size() {
return this.top
}

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

// To see all the elements in the stack
Stack.prototype.view = function (output = (value) => console.log(value)) {
view(output = (value) => console.log(value)) {
for (let i = 0; i < this.top; i++) {
output(this.stack[i])
}
}

return Stack
})()
}

export { Stack }
Loading