How to change the position of an array element?

后端 未结 7 820
Happy的楠姐
Happy的楠姐 2020-12-24 06:45

I have a question on how I can change the index of a array element, so that it doesn\'t come at the 7. position but at position 2 instead...

Is there a function to h

7条回答
  •  情深已故
    2020-12-24 06:57

    Isn't better to use:

    irb> a = [2,5,4,6]
    #=> [2, 5, 4, 6]
    irb> a.insert(1, a.pop)
    #=> [2, 6, 5, 4]
    

    ?

提交回复
热议问题