Created
December 16, 2013 03:27
-
-
Save fenixbrassi/7981877 to your computer and use it in GitHub Desktop.
The longes string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def give_the_longest(array_strings) | |
longest_string = "" | |
array_strings.split(',').each do |x| | |
if x.length > longest_string.length | |
longest_string = x | |
end | |
end | |
longest_string | |
end | |
puts "Give me 5 strings separete by commas" | |
words = gets | |
puts "\n" | |
puts "The longest string is: #{give_the_longest | |
(words)}" | |
------------------- | |
Result console is: | |
C:\Training>ruby longest_string.rb | |
Give me 5 strings separete by commas | |
asfasdf,asfas,fa,sf,as,df,as,fa,s,fa,sdf,a,sf,as,dff,a | |
sfafdasfasfasfasfasdfasdfa | |
sfasdf2 | |
The longest string is: | |
asfafdasfasfasfasfasdfasdfas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment