-
Notifications
You must be signed in to change notification settings - Fork 48
Leaves - Yitgop #35
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?
Leaves - Yitgop #35
Conversation
CheezItMan
left a comment
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.
Nice work. You hit the learning goals here. Check out my comments and let me know if you have any questions.
lib/reverse_sentence.rb
Outdated
| def pairs_helper(length) | ||
| if length % 2 == 0 | ||
| pairs = length / 2 | ||
| else | ||
| pairs = (length - 1) / 2 | ||
| end | ||
| return pairs |
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.
I don't think this method is really needed as dividing an odd length by 2 will automatically round down.
lib/reverse_sentence.rb
Outdated
| (sentence_pairs).times do | ||
| temp = my_sentence[i-1] | ||
| my_sentence[i-1] = my_sentence[-i] | ||
| my_sentence[-i] = temp | ||
| i += 1 |
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.
Notice that you're reversing a couple of times in this method. Could you instead make a helper method. That would dry this out.
lib/reverse_sentence.rb
Outdated
| def reverse_sentence(my_sentence) | ||
| raise NotImplementedError | ||
| # Time complexity: O(n2) | ||
| # Space complexity: O(n) |
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.
Correct where n is the number of words.
lib/sort_by_length.rb
Outdated
| # Time complexity: O(n2) | ||
| # Space complexity: O(n) | ||
|
|
||
| def sort_by_length(my_sentence) |
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.
Nice bubblesort
Sorting & Reverse Sentence