Skip to content

Instantly share code, notes, and snippets.

@mistrikushal
Created January 26, 2016 13:52
Show Gist options
  • Save mistrikushal/e6a8cb75166f75e78bd9 to your computer and use it in GitHub Desktop.
Save mistrikushal/e6a8cb75166f75e78bd9 to your computer and use it in GitHub Desktop.
find a longest word from a given string
# logic to check longest word from a string
str = 'this string contains a looooooong word'
longest_word = str.split(' ').max_by(&:length)
puts "Longest word of the string is: #{longest_word}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment