I just looked at the solution branch for this lab and I think that this lab should be dialed down a bit, because I felt like I had an arm tied behind my back.
I used a bunch of searches like the following:
"find the lowest value in a hash ruby using each"
"iterate over a hash to return the lowest value without using .sort ruby"
"find lowest value in a hash without using sort ruby"
"lowest value in a hash without using .min"
"compare values in an array to find the lowest ruby"
As many of my search results began to overlap I really had no idea how to complete this lab without using .keys
, .values
,.min
, .sort
, or .min_by
. All of the searches were answered using the "off-limits" methods. Then for the first time I resorted to looking at the solution branch like I mentioned earlier.
Look at the solution code:
def key_for_min_value(hash)
lowest_key = nil
lowest_value = Float::INFINITY
hash.each do |k, v|
if v < lowest_value
lowest_value = v
lowest_key = k
end
end
lowest_key
end
Bringing your attention to the use of Float::INFINITY
. That's great that this method works it's why I can go on to learn more about hashes and not be stuck in "Ask" limbo; however, being someone who has taken up coding just two months ago classes aren't in my wheelhouse just yet and I wouldn't have ever thought to use something like Float::INFINITY
. This is something that has not been covered in the curriculum and it's a real curve ball for people doing this for the first time. The file key_for_min.rb
gives us this line: # prereqs: iterators, hashes, conditional logic
, never mentioning classes or what Float
even does.
I found the most relevant lab to this one was this one on sorting, yet it teaches us how to use a method that is off limits in this lab. I constructed this method just to see if I could achieve the goal of this lab:
def completes(name_hash) # This also works for this lab.
name_hash.sort do |x,y|
x <=> y
end.first[0]
end
It passed the first test and failed the last two which surprised me.
Take aways here:
- This lab is placed in a really odd spot in the flow of the curriculum. I feel like it's saying "before you learn about all these methods we won't let you use, use your previous knowledge to complete this lab. Which according to how we have solved it the solution relies on something never covered.
- Dial down the difficulty This can be accomplished by simply taking away the restrictions or even adding a third "Helpful Hint" that links to a real helpful hint, introducing the Float class
- Fix the tests. I looked at both files in the spec folder and I did not see any indication that the "off-limits" methods were indeed off limits which makes me wonder why the
completes
method I copy and pasted above only passed one test, I at least expected it to pass the second.