0

Random Letter Checker

I can pass 1, 3, & 4 tests for both ways. There is something I am missing because they both will not output “Deja Vu”. What am I overlooking? Way#1 #test 1, 3, 4 passed def repeating_letters?(str) repeating_letters = gets seen = [str] str.each_char do |letter| if seen.include?(letter) return "Deja Vu" else return "Unique" end end end puts repeating_letters?("a..z") Way#2 #test 1, 3, 4 passed repeating_letters = gets def repeating_letters(str) for i in ('a'..'z') if str.count(i) > 1 return "Deja Vu" else return "Unique" end end end puts repeating_letters("a".."z")

18th Dec 2020, 2:03 AM
Joy Shadburn
Joy Shadburn - avatar
1 ответ
0
In both ways. You only test first letter, because you instantly return after as soon as the loop starts. Place return "Unique" out of the for loop and remove else statement.
18th Dec 2020, 2:12 AM
你知道規則,我也是
你知道規則,我也是 - avatar