LoginSignup
1
1

More than 3 years have passed since last update.

Ruby 配列の中の値の最小値を抽出するアルゴリズム

Posted at

こんにちは、おすしです。

a = [11, 2, 3, 4, 213, 5, 6]

def search(ary)
  for i in 1..(ary.count - 1) do
    if ary[0] > ary[i]
      ary[0] = ary[i]
    end
  end
  return ary[0]
end

p search(a)

↑コピペして実行してみてください。
配列の中にある値の最小値を求めるアルゴリズムです。

ご覧いただきありがとうございます♪(´ε` )

1
1
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
1
1