Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from TheAlgorithms:master #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 1 commit into AlgorithmAndLeetCode:master from TheAlgorithms:master
Apr 14, 2024
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
chore: convert functions to an ES2015 classes (TheAlgorithms#1656)
* chore: convert functions to an ES2015 classes
* remove unnecessary functions
  • Loading branch information
hasanalkaf3 authored Apr 13, 2024
commit 6fe21d21e92d4f07b476d56fbcad838633e74550
4 changes: 2 additions & 2 deletions Conversions/RailwayTimeConversion.js
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /