LoginSignup
6
2

More than 5 years have passed since last update.

reduceでwith_indexする方法

Posted at

以下の方法で出来ると思ったらできなかった

# これはダメ
words.reduce.with_index do |array, word, index|
  中略~
end

each_with_indexをreduceに渡したら出来た

# これでOK
words.each_with_index.reduce do |array, (word, index)|
  中略
end
6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2