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

Rachel Lyons #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/find_non_repeated_letter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@


def find_first_non_repeated_letter(str)
#write your method here
return true
i = 0

if str[i] != str[i+1]
return str[0]
else
while i < str.length
if str[i] == str[i+1]
i += 1
elsif str[i+1] == str[i+2]

Choose a reason for hiding this comment

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

Can you say more about your inclusion of this elsif block? What was your thought process for including it? If you comment it out, does your method still function properly? Why or why not?

Copy link
Author

Choose a reason for hiding this comment

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

If the first two characters in a given string are the same, the if statement in the while loop will find when they are no longer the same. Say str = "aaabbbbc". In this case the if statement would run through twice, but the third time the elsif statement would run because "a" != "b". "b" could be the first non-repeated letter, but there has to be a way to check if "b" is followed by another "b" or a different character. This is what the elsif block is for. When the elsif block is commented out the method does not work properly. If str = "aaabbbbc", without the elsif block, the letter "b" would be returned instead of "c".

i += 1
else
return str[i+1]
end
end
end
return nil
end