Compare 2 Arrays of class

Hello, today I have a problem in my project, I would like to check if 2 arrays of SoftwareDependency class have the same content, but I have this error:

if nextDependenciesArray.sort == currentDependenciesArray.sort
                            inextricableDependency = true
                            inextricableArrayTest = currentDependenciesArray
                            break
                        end
 zohran   master  ~  ISM  1  crystal Main.cr -so -i libstdc++-pass1 gcc-pass1
Showing last frame. Use --error-trace for full trace.

In /usr/lib64/crystal/slice/sort.cr:199:12

 199 | v = v1 <=> v2
              ^--
Error: undefined method '<=>' for ISM::SoftwareDependency

All array are Array(ISM::SoftwareDependency).

And Is it possible to perform a uniq! in an array like that as well ?

You should look into including Comparable(T) - Crystal 1.2.2 into your ISM::SoftwareDependency type.

1 Like

To clarify, the issue isn’t with your arrays, it’s that you don’t have a way to compare your ISM::SoftwareDependency instances.

I solved my problem finally with an another way, and it was better, sorry if I didn’t replied directly, I’m busy with my project actually. Thanks you so much for your help !