Skip to content

Completed Longest Word Project in Ruby #4047

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

Closed
wants to merge 3 commits into from
Closed
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
28 changes: 28 additions & 0 deletions archive/r/ruby/LongestWord.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def longest_word_length(input)

# Split the input by spaces
words = input.split(" ")

# Start with 0 as the longest length
max_length = 0

# Go through each word
words.each do |word|
if word.length > max_length
max_length = word.length
end
end

# Return the length of the longest word
max_length
end

# Check if the program has received input from the command line
if ARGV.length > 0
input_string = ARGV.join(" ")
puts longest_word_length(input_string)
else
puts "Please provide an input string."
end