vendredi 12 juin 2020

How to sort an array based on enum hash and return the maximum in Ruby?

enum custom: {
   AB1:  1,
   AB45: 10,
   XY:   15
}

Input:

array = [AB45, XY]

Output should be: XY as XY is maximum based on the value's value (I mean value of key XY is highest).

I tried the following: MyClassName.customs.values_at(*array) . This returns [10,15]

Aucun commentaire:

Enregistrer un commentaire