Movatterモバイル変換


[0]ホーム

URL:


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

chore: convert functions to an ES2015 classes#1656

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
raklaptudirm merged 2 commits intoTheAlgorithms:masterfromhasanalkaf3:master
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionsConversions/RailwayTimeConversion.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsData-Structures/Array/Reverse.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsData-Structures/Stack/Stack.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp