Skip to content
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

Carly - Edges - Reverse_sentence algorithm. #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CarlyReiter
Copy link

Once I actually understood the reverse_words (thanks for providing the solution - much help!), this alogorithm came quite easily to me.

end

length = my_sentence.length
i = 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider calling the string_reverse method you created above passing in start_index as 0 and end_index as length-1. That way, you'll avoid code repetition.

end
end_index = i - 1

reversed_string = string_reverse(my_words, start_index, end_index)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that all the string manipulations are happening in-place in this file, you don't need to return anything from the methods or assign anything. e.g. lines 43 could simply be string_reverse(my_words, start_index, end_index) and line 46 can simply be return. The same applies to all other methods.

@shrutivanw
Copy link

Nice work! I added some comments inline for further improvements.

I also didn't see any comments on the time and space complexities. Take a look at another similar solution and the time and space complexity here: https://github.com/Ada-C10/reverse_sentence/blob/solution/lib/reverse_sentence.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants