Array#rotate equivalent in ruby 1.8.7

前端 未结 4 949
南笙
南笙 2021-01-13 00:55
a = [ \"a\", \"b\", \"c\", \"d\" ]
a.rotate         #=> [\"b\", \"c\", \"d\", \"a\"]

#rotate is a method of Array in R

4条回答
  •  天命终不由人
    2021-01-13 01:32

    You can achieve the same with a.push(a.shift). It basically removes the first element (shift) and appends it to the end (push).

提交回复
热议问题