-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex25.rb
40 lines (34 loc) · 844 Bytes
/
ex25.rb
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
module Ex25
def Ex25.break_words(stuff)
stuff.split(' ')
end
# Sorts the words.
def Ex25.sort_words(words)
words.sort
end
def Ex25.print_first_word(words)
word = words.shift
puts word
end
def Ex25.print_last_word(words)
word = words.pop
puts word
end
# Takes in a full sentence and returns the sorted words.
def Ex25.sort_sentence(sentence)
words = Ex25.break_words(sentence)
Ex25.sort_words(words)
end
# Prints the first and last words of the sentence.
def Ex25.print_first_and_last(sentence)
words = Ex25.break_words(sentence)
Ex25.print_first_word(words)
Ex25.print_last_word(words)
end
# Sorts the words then prints the first and last one.
def Ex25.print_first_and_last_sorted(sentence)
words = Ex25.sort_sentence(sentence)
Ex25.print_first_word(words)
Ex25.print_last_word(words)
end
end