Common_element.rb
This content was produced by an LLM and could include errors.
This script finds the common element between two Ruby arrays, a and b. It demonstrates two methods—using the intersection operator (&) and the find method—both successfully locating the shared value, "l9ma".
a = ["z3qx", "l9ma", "b77r", "x1p0"]
#=> ["z3qx", "l9ma", "b77r", "x1p0"]
b = ["x1p0", "l9ma", "wxyz"]
#=> ["x1p0", "l9ma", "wxyz"]
(a & b).sort.first
#=> "l9ma"
a.find { |x| b.include?(x) }
#=> "l9ma"
Ruby 4.0.3