A
A
Andrey2018-02-09 13:37:11
Ruby on Rails
Andrey, 2018-02-09 13:37:11

How to assign an element in a hash array with index 0?

I have an array of hashes

hash = [
  {:name=>"Автомобили"},
  {:name=>"Мотоциклы"},
  {:name=>"Квадроциклы"},
  {:name=>"Грузовики"}
]

It is necessary to sort so that if , then put this hash in the first place. those. give it index 0hash[:name] == "Грузовики"
hash = [
  {:name=>"Грузовики"},
  {:name=>"Автомобили"},
  {:name=>"Мотоциклы"},
  {:name=>"Квадроциклы"}  
]

If it's not in the array, then do nothing.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alfss, 2018-02-09
@alfss

Take it out and put it on top of the stack or create a new list in the correct order or enter the weights and sort by them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question