forked from codeunion/ruby-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_max.rb
More file actions
31 lines (26 loc) · 837 Bytes
/
count_max.rb
File metadata and controls
31 lines (26 loc) · 837 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
# Method name: count_max
# Inputs: A list of numbers
# Returns: The number of times the largest number in the list
# appears in the list
# Prints: Nothing
#
# For example,
# count_max([10, 1,2,10,10]) == 3
# because "10" is the largest number in the list and it occurs 3 times
# This is how we require the max.rb and count_in_list.rb files in the current folder.
# We can now use the "max" and "count_in_list" methods we defined there — justs
# as if we had defined them here!
require_relative './max'
require_relative './count_in_list'
def count_max(list)
max = max(list)
count = count_in_list(list, max)
count
end
if __FILE__ == $0
p count_max([1,2,3]) == 1
p count_max([1,2,3, 3, 3]) == 3
p count_max([1,1,1]) == 3
p count_max([-1,-2,-3]) == 1
p count_max([-1,-1, -2,-3]) == 2
end