-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path25_mod.rb
More file actions
38 lines (30 loc) · 1.05 KB
/
25_mod.rb
File metadata and controls
38 lines (30 loc) · 1.05 KB
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
module Ex25
# This function will break up words for us.
def Ex25.break_words(stuff)
words = stuff.split(' ')
return words
end
def Ex25.sort_words(words) #self
return break_words(words).sort
end
# Prints the first word after shifting it off.
def Ex25.print_first_word(words) #se implicito, non riesco a chiamarlo dal modulo stesso
return break_words(words).shift
end
# Prints the last word after popping it off.
def Ex25.print_last_word(words)
return break_words(words).pop
end
# Takes in a full sentence and returns the sorted words.
def Ex25.sort_sentence(sentence)
return Ex25.sort_words(sentence)
end
# Prints the first and last words of the sentence.
def Ex25.print_first_and_last(sentence)
return Ex25.print_first_word(sentence) , Ex25.print_last_word(sentence)
end
# Sorts the words then prints the first and last one.
def Ex25.print_first_and_last_sorted(sentence)
return sentence.split(' ').sort.first , sentence.split(' ').sort.last
end
end