Skip to content
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

Fix/code smells #1338

Merged
merged 9 commits into from
Aug 21, 2023
Merged

Conversation

CarlosZoft
Copy link
Member

Open in Gitpod know more

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Some minor algorithm fixes

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new JavaScript files are placed inside an existing directory.
  • All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames.
    Example:UserProfile.js is allowed but userprofile.js,Userprofile.js,user-Profile.js,userProfile.js are not
  • All new algorithms have a URL in their comments that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

appgurueu
appgurueu previously approved these changes Jul 21, 2023
Copy link
Collaborator

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely an improvement overall. I have some minor comments.

@CarlosZoft
Copy link
Member Author

Ohh nice, tks for review. i'll fix this today xD

@CarlosZoft
Copy link
Member Author

@appgurueu, sorry for the delay, fixed the issues ✅

@raklaptudirm raklaptudirm merged commit 00e40e6 into TheAlgorithms:master Aug 21, 2023
2 checks passed
Copy link

@badr222222 badr222222 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the data base was mest up at first but think if there was a few of us we can do it

Copy link

@badr222222 badr222222 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

23 changes: 12 additions & 11 deletions 23
Sorts/SimplifiedWiggleSort.js
Viewed

@@ -8,29 +8,30 @@
import { quickSelectSearch } from '../Search/QuickSelectSearch.js'

export const simplifiedWiggleSort = function (arr) {
const arrSize = arr.length
CarlosZoft marked this conversation as resolved.
// find Median using QuickSelect
let median = quickSelectSearch(arr, Math.floor(arr.length / 2.0))
median = median[Math.floor(arr.length / 2.0)]
let median = quickSelectSearch(arr, Math.floor(arrSize / 2.0))
median = median[Math.floor(arrSize / 2.0)]

const sorted = new Array(arr.length)
const sorted = new Array(arrSize)

let smallerThanMedianIndx = 0
let greaterThanMedianIndx = arr.length - 1 - (arr.length % 2)
let greaterThanMedianIndx = arrSize - 1 - (arrSize % 2)

for (let i = 0; i < arr.length; i++) {
if (arr[i] > median) {
sorted[greaterThanMedianIndx] = arr[i]
arr.forEach(element => {
if (element > median) {
sorted[greaterThanMedianIndx] = element
greaterThanMedianIndx -= 2
} else {
if (smallerThanMedianIndx < arr.length) {
sorted[smallerThanMedianIndx] = arr[i]
if (smallerThanMedianIndx < arrSize) {
sorted[smallerThanMedianIndx] = element
smallerThanMedianIndx += 2
} else {
sorted[greaterThanMedianIndx] = arr[i]
sorted[greaterThanMedianIndx] = element
greaterThanMedianIndx -= 2
}
}
}
})

return sorted
}
2 changes: 1 addition & 1 deletion 2
String/CheckRearrangePalindrome.js
Viewed

@@ -12,7 +12,7 @@ export const palindromeRearranging = (str) => {
return 'Not a string'
}
// Check if is a empty string
if (str.length === 0) {
if (!str) {
return 'Empty string'
}

Use this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants