Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def longestWord(text)
- array = Array.new
- array_length = text.length
- x = 0
- y = 0
- string = ""
- while (x < array_length)
- if ((text[x] >= 'A' and text[x] <= 'Z') or (text[x] >= 'a' and text[x] <= 'z')) then
- string = string + text[x]
- else
- array[y] = string
- y = y + 1
- string = ""
- end
- x = x + 1
- end
- array[y] = string
- return array.max_by(&:length)
- end
Advertisement
Add Comment
Please, Sign In to add comment