array.map! starting at index other than 0

后端 未结 0 1202
梦谈多话
梦谈多话 2021-01-16 23:40

I am trying to mutate an array using map!, but starting index 1 and leaving index 0 unchanged:

test = [1, 2, 3, 4]
test[1..-1].map!{ |n| n += 2 }   
puts test         


        
相关标签:
回答
  • 消灭零回复
提交回复
热议问题