-
Notifications
You must be signed in to change notification settings - Fork 48
Leaves - Elizabeth #44
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?
Conversation
…igure out how toget it to pass all the tests.
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.
Not bad, your reverse_sentence isn't done in place, but it mostly works. The sort works, but it isn't a bubble, insertion or selection sort. Take a look at my comments and let me know your questions.
| end | ||
|
|
||
| if i == mid | ||
| my_sentence = words.join(", ") |
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.
Take a look at my how functions work lesson. Doing this doesn't affect the argument, which is why the tests fail.
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n) because the amount of time it will take will increase as the length of the input increases. | ||
| # Space complexity: O(n) because the space increases as the inout increases. |
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.
You were asked to try to do this in place which mean O(1) space complexity. Can you see a way?
| while index < word_array.length | ||
| if word.length < sorted[index].length | ||
| sorted.insert(index, word) | ||
| break | ||
| elsif word.length == sorted[index].length | ||
| sorted.insert(index+1,word) | ||
| break | ||
| elsif index == sorted.length-1 | ||
| sorted.insert(index+1,word) | ||
| break | ||
| end | ||
| index += 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.
This is a very strange nonstandard sort. It works, but does a lot of extra inserts. Take a look at the textbook curriculum lesson on sorting and compare this to the standard sorts.
Sorting & Reverse Sentence