-
Notifications
You must be signed in to change notification settings - Fork 47
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
Maryam's reverse words #27
base: master
Are you sure you want to change the base?
Conversation
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.
we solved this one in different ways, but i think yours is very clever how you use nil, true, and false values to keep track. i wouldn't have thought of it, and i feel like i learned something new!
finish = nil | ||
|
||
while current_index < my_words.length | ||
currently_on_letter = my_words[current_index] != " " |
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 haven't seen this before - is it just returning true or false?
end | ||
|
||
if start && finish | ||
reverse_one_word(my_words, start, finish) |
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 like that you split it into different functions - easy to follow
first_letter = word[i] | ||
last_letter = word[index] | ||
|
||
word[i] = last_letter |
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.
Idea for further improvement: can you swap using only one temporary variable instead of two as you have now?
index -= 1 | ||
end | ||
|
||
return word |
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 reversing in place, you don't need to return word. Line 23 could simply be return
Nice work! 👍 I didn't see any comments or description on the time and space complexity. Take a read of the explanations on https://github.com/Ada-C10/reverse_words/blob/solution/lib/reverse_words.rb Slack me if you have any questions. |
No description provided.