In the Odin discord, someone posted the following "solution" to the #find_favorite exercise in nested_array_exercises.rb where the goal is to write a method that takes an array of hash objects and returns the hash object with the key: value pair of is_my_favorite?: true -- or nil if no such hash object exists.
def find_favorite(array_of_hash_objects)
array_of_hash_objects.each do |data|
if data[:is_my_favorite?] == true
return data
else
return nil
end
end
end
The case that's true for the first element in array_of_hash_objects is what will get returned from the method, which doesn't solve the problem of returning the hash with the key: value pair of is_my_favorite?: true. However since the tests for this method (which are here) only ever provide an array with a hash holding :is_my_favorite?: true at the 0th index, the tests pass for this solution just fine. I'd like to submit a PR that properly fails the above code by either:
Adding a test case that has the { name: 'Ruby', is_my_favorite?: true } hash at a non-zero index of the let array.
Just changing the existing test case to place the { name: 'Ruby', is_my_favorite?: true} at a non-zero index of the let array. I think it could be fine to just stick with the one case and place it in the middle of the array at index 1, as it seems unlikely someone would stumble into writing something that passes with it in the middle of the array while also not being a true solution to the problem.
@JoshDevHub Thanks for making this issue. I think changing the existing test case is the best option, as you explained. When you make a PR, please reference this issue. π
In the Odin discord, someone posted the following "solution" to the
#find_favorite
exercise innested_array_exercises.rb
where the goal is to write a method that takes an array of hash objects and returns the hash object with the key: value pair ofis_my_favorite?: true
-- ornil
if no such hash object exists.The case that's true for the first element in
array_of_hash_objects
is what will get returned from the method, which doesn't solve the problem of returning the hash with the key: value pair ofis_my_favorite?: true
. However since the tests for this method (which are here) only ever provide an array with a hash holding:is_my_favorite?: true
at the 0th index, the tests pass for this solution just fine. I'd like to submit a PR that properly fails the above code by either:{ name: 'Ruby', is_my_favorite?: true }
hash at a non-zero index of thelet
array.{ name: 'Ruby', is_my_favorite?: true}
at a non-zero index of thelet
array. I think it could be fine to just stick with the one case and place it in the middle of the array at index 1, as it seems unlikely someone would stumble into writing something that passes with it in the middle of the array while also not being a true solution to the problem.Let me know what you think π