diff --git a/06_breadth-first_search/ruby/01_breadth-first_search.rb b/06_breadth-first_search/ruby/01_breadth-first_search.rb index a47e0d0..2aa15f3 100644 --- a/06_breadth-first_search/ruby/01_breadth-first_search.rb +++ b/06_breadth-first_search/ruby/01_breadth-first_search.rb @@ -18,16 +18,16 @@ def search(name) search_queue = [] search_queue += @graph[name] # This array is how you keep track of which people you've searched before. - searched = [] + searched = {} until search_queue.empty? person = search_queue.shift # Only search this person if you haven't already searched them. - next if searched.member?(person) + next if searched[person] return person if yield person search_queue += @graph[person] # Marks this person as searched - searched.push(person) + searched[person] = true end false