Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work you hit all the learning goals. Your reverse_sentence method could use a bit of a refactor as many of your methods are very repetitive. Other than that, excellent work.
| # A method to reverse the words in a sentence, in place. | ||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(2n) The array is reviewed twice, once for spaces to populate the space array, and once more piecewise to do all the swaps |
| until i == half_swap_limit | ||
| my_sentence[i], my_sentence[last_index - i] = my_sentence[last_index - i], my_sentence[i] | ||
|
|
||
| i += 1 |
There was a problem hiding this comment.
Notice that you reverse things a few times, this could be dryed up with a helper method.
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(2n) The array is reviewed twice, once for spaces to populate the space array, and once more piecewise to do all the swaps | ||
| # Space complexity: O(1) |
There was a problem hiding this comment.
You are building a space array, so this would actually be: O(m) where m is the number of words.
| return my_sentence | ||
|
|
||
| end | ||
|
|
There was a problem hiding this comment.
These methods seem pretty repetitive. Could they be condensed into one method?
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n2) | ||
| # Space complexity: O(1) |
There was a problem hiding this comment.
Technically since you're doing .split, this should be O(n)
|
|
||
| if array_of_sentence[i].length > array_of_sentence[i + 1].length | ||
| array_of_sentence[i], array_of_sentence[i + 1] = array_of_sentence[i + 1], array_of_sentence[i] | ||
| i += 1 |
There was a problem hiding this comment.
You could move the i += 1 to after the if statement and drop the else.
Sorting & Reverse Sentence