-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_solution.rb
85 lines (66 loc) · 2.36 KB
/
my_solution.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# U2.W4: Research Methods
i_want_pets = ["I", "want", 3, "pets", "but", "I", "only", "have", 2]
my_family_pets_ages = {"Evi" => 6, "Hoobie" => 3, "George" => 12, "Bogart" => 4, "Poly" => 4,
"Annabelle" => 0, "Ditto" => 3}
# Person 1's solution
def my_array_finding_method(source, thing_to_find)
# Your code here!
end
def my_hash_finding_method(source, thing_to_find)
# Your code here!
end
# Identify and describe the ruby method you implemented.
#
#
#
# Person 2
def my_array_modification_method(source, thing_to_modify)
# Your code here!
end
def my_hash_modification_method(source, thing_to_modify)
# Your code here!
end
# Identify and describe the ruby method you implemented.
#
#
#
# Person 3
def my_array_sorting_method(source)
# Your code here!
end
def my_hash_sorting_method(source)
# Your code here!
end
# Identify and describe the ruby method you implemented.
#
#
#
# Person 4
def my_array_deletion_method(source, thing_to_delete)
#Your code here!
end
def my_hash_deletion_method(source, thing_to_delete)
#Your code here!
end
# Identify and describe the ruby method you implemented.
#
#
#
################## DRIVER CODE ###################################
# HINT: Use `puts` statements to see if you are altering the original structure with these methods.
# Each of these should return `true` if they are implemented properly.
p my_array_finding_method(i_want_pets, "t") == ["want","pets","but"]
p my_hash_finding_method(my_family_pets_ages, 3) == ["Hoobie", "Ditto"]
p my_array_modification_method(i_want_pets, 1) == ["I", "want", 4, "pets", "but", "I", "only", "have", 3 ]
p my_hash_modification_method(my_family_pets_ages, 2) == {"Evi" => 8, "Hoobie" => 5, "George" => 14, "Bogart" => 6, "Poly" => 6, "Annabelle" => 2, "Ditto" => 5}
p my_array_sorting_method(i_want_pets) == ["3", "4", "I", "but", "have", "only", "pets", "want"]
p my_hash_sorting_method(my_family_pets_ages) == [["Annabelle", 2], ["Ditto", 5], ["Hoobie", 5], ["Bogart", 6], ["Poly", 6], ["Evi", 8], ["George", 14]]
# This may be false depending on how your method deals with ordering the animals with the same ages.
p my_array_deletion_method(i_want_pets, "a") == ["I", 4, "pets", "but", "I", "only", 3 ]
p my_hash_deletion_method(my_family_pets_ages, "George") == {"Evi" => 8, "Hoobie" => 5, "Bogart" => 6, "Poly" => 6, "Annabelle" => 2, "Ditto" => 5}
# Reflect!
#
#
#
#
#