-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetterCount.rb
More file actions
47 lines (41 loc) · 1014 Bytes
/
LetterCount.rb
File metadata and controls
47 lines (41 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#Using the Ruby language, have the function LetterCountI(str) take the
#str parameter being passed and return the first word with the greatest
#number of repeated letters. For example: "Today, is the greatest day ever!"
#should return greatest because it has 2 e's (and 2 t's) and it comes
#before ever which also has 2 e's. If there are no words with repeating
#letters return -1. Words will be separated by spaces.
def LetterCountI(str)
str = str.split
i = 0
j = 0
repeat = 0
count = 0
gr_word = ""
while i < str.length
word = str[i].split("").sort
while j < word.length
puts word[j]
puts word[j + 1]
if word[j] == word [j+1]
puts word[j]
repeat += 1
else
repeat = 0
end
if repeat > count
count = repeat
gr_word = str[i]
end
repeat = 0
j += 1
end
j = 0
i += 1
end
if gr_word == ""
return -1
else
return gr_word
end
end
LetterCountI("no words here")