DEV Community

Discussion on: Daily Challenge #213 - Are they the "same"?

Collapse
 
nilbert profile image
Nilbert

Ruby

def comp(array1, array2)
  return false if array1.nil?  || array2.nil?
    #method 1 compare dic
    array1.map{|x| x*x}.group_by(&:itself) == array2.group_by(&:itself)
    #method 2 compare sorted array
    array1.sort.map {|x| x*x} == array2.sort
end