-
Notifications
You must be signed in to change notification settings - Fork 48
Branches, Kristy #32
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?
Branches, Kristy #32
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.
Not bad, check out my comments and let me know if you have any questions.
| @@ -1,6 +1,28 @@ | |||
| # A method to reverse the words in a sentence, in place. | |||
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.
No comprehension question answers.
| i += 1 | ||
| j -= 1 | ||
| end | ||
| my_sentence = reverse.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.
See my lesson on how functions work This isn't changing the original argument.
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(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.
Since you're doing .scan you end up with O(n) because it's making a new array.
| # sorted by the length of the word. | ||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time 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.
This is O(n2). Check out your nested loops.
| while i < my_array.length | ||
| to_insert = my_array[i] | ||
| j = i | ||
|
|
||
| while j > 0 && my_array[j-1].length > to_insert.length | ||
| my_array[j] = my_array[j-1] | ||
| j -= 1 | ||
| end | ||
| my_array[j] = to_insert | ||
| i += 1 | ||
| 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.
Nice insertion sort.
Sorting & Reverse Sentence