-
Notifications
You must be signed in to change notification settings - Fork 2
PR #6 #6
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
base: master
Are you sure you want to change the base?
PR #6 #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
|
|
||
| def sort(array) | ||
| if array == nil || array.length <= 1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice base case! |
||
| return array # nothing to sort | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it return nil if there is no array? |
||
| end | ||
|
|
||
| index = 0 | ||
| swapped = true | ||
| while index < array.length && swapped | ||
| swapped = false | ||
| other_index = index + 1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe since it's the next index the variable should be called next_index instead of other_index |
||
| while other_index < array.length | ||
| if array[index] > array[other_index] | ||
| temp = array[index] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a more descriptive variable name than "temp" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rename |
||
| array[index] = array[other_index] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming. Index / Other_index can get a little confusing. |
||
| array[other_index] = temp | ||
| swapped = true | ||
|
Comment on lines
+13
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great use of temp variable here |
||
| end | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit confusing here, could we add some clarifying comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe parallel assignment would make this more readable instead of using temp |
||
| other_index += 1 | ||
| end | ||
| index += 1 | ||
| end | ||
|
Comment on lines
+7
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bubble sort? A few comments might be helpful for those of us who don't understand what this is doing at first glance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i agree |
||
|
|
||
| return array | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a comment describing the sorting algorithm could be helpful for comprehension