リモートで働くプログラマーの検索結果

リモ太がググったことの覚書

rubyでeach_with_indexみたいなことをmapでもやりたい

with_indexをmapにつなげて書けばよいようだ

array = ['apple', 'peach', 'orange']
p array.map.with_index{|v, index| index > 1 ? 'hoge' : v}
=> ["apple", "peach", "hoge"]