-
Notifications
You must be signed in to change notification settings - Fork 60
/
pad_array.rb
43 lines (35 loc) · 1.36 KB
/
pad_array.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
41
42
43
# Method name: pad_array
# Inputs: An array, a minimum size, and a padding element
# Returns: An array which has been padded with the padding element
# if the array is smaller than the minimum size
# Prints: Nothing
# For example,
#
# pad_array([1,2,3], 5, "waffles") == [1,2,3,"waffles","waffles"]
# pad_array([1,2,3], 4, "waffles") == [1,2,3,"waffles"]
# pad_array([1,2,3], 3, "waffles") == [1,2,3]
# Note #1
# Remember, use Array#push if you want to append something to an array
# http://www.ruby-doc.org/core-2.1.2/Array.html#method-i-push
#
# It works like this:
#
# array = [1,2,3]
# array.push("waffles")
# array == [1,2,3,"waffles"]
def pad_array(array, min_size, pad_with)
end
if __FILE__ == $PROGRAM_NAME
# Here are some sanity checks written in "plain English".
# See if you can translate them into Ruby. Your checks should look like
#
# p pad_array(input) == ...expected return value...
# If min_size is 0
# then pad_array should always return the input array
# If min_size is less than the size of the input array
# then pad_array should always return the input array
# If min_size equals the size of the input array
# then pad_array should always return the input array
# If min_size is 1 greater than the size of the input array
# then pad_array should add a single item to the end of the input array
end