LoginSignup
4
0

More than 3 years have passed since last update.

ruby 配列の中身の差

Posted at

Rubyの配列の中身の差を求める。

array.rb
array = [1, 6, 8, 15, 18, 25]
array.each_cons(2) do |l, r|
   puts (r - l).abs
end
実行結果
5
2
7
8
3
7

参考資料
https://ref.xaio.jp/ruby/classes/enumerable/each_cons
https://teratail.com/questions/115298
https://www.javadrive.jp/ruby/numeric_class/index7.html

4
0
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
4
0