るりまサーチ

最速Rubyリファレンスマニュアル検索!
98件ヒット [1-98件を表示] (0.027秒)
トップページ > クエリ:max[x] > クエリ:max_by[x]

別のキーワード

  1. _builtin max
  2. _builtin max_by
  3. enumerable max_by
  4. enumerable max
  5. range max

ライブラリ

モジュール

キーワード

検索結果

Enumerable#max_by -> Enumerator (24322.0)

各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。

...

Enumerable#max と Enumerable#max_by
違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。

ブロックを省略した場合は Enumerator を返します。

@param n 取得する要素数。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by...
..."horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}

//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #<Enumerator: ["albatross", "dog", "horse"]:max_by(2)>
a.max_by(2) {|x| x.length } # => ["albatross", "horse"]
//}

//emlist[例: enum.max_by(n)...
...# Weighted random sampling with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a...

Enumerable#max_by {|item| ... } -> object | nil (24322.0)

各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。

...

Enumerable#max と Enumerable#max_by
違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。

ブロックを省略した場合は Enumerator を返します。

@param n 取得する要素数。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by...
..."horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}

//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #<Enumerator: ["albatross", "dog", "horse"]:max_by(2)>
a.max_by(2) {|x| x.length } # => ["albatross", "horse"]
//}

//emlist[例: enum.max_by(n)...
...# Weighted random sampling with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a...

Enumerable#max_by(n) -> Enumerator (24322.0)

各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。

...

Enumerable#max と Enumerable#max_by
違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。

ブロックを省略した場合は Enumerator を返します。

@param n 取得する要素数。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by...
..."horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}

//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #<Enumerator: ["albatross", "dog", "horse"]:max_by(2)>
a.max_by(2) {|x| x.length } # => ["albatross", "horse"]
//}

//emlist[例: enum.max_by(n)...
...# Weighted random sampling with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a...

Enumerable#max_by(n) {|item| ... } -> Array (24322.0)

各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。

...

Enumerable#max と Enumerable#max_by
違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。

ブロックを省略した場合は Enumerator を返します。

@param n 取得する要素数。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by...
..."horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}

//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #<Enumerator: ["albatross", "dog", "horse"]:max_by(2)>
a.max_by(2) {|x| x.length } # => ["albatross", "horse"]
//}

//emlist[例: enum.max_by(n)...
...# Weighted random sampling with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a...

Enumerable#minmax_by -> Enumerator (12200.0)

Enumerable オブジェクトの各要素をブロックに渡して評価し、その結果を <=> で比較して 最小の要素と最大の要素を要素とするサイズ 2 の配列を返します。

...Enumerable#minmax と Enumerable#minmax_by
違いは sort と sort_by の違いと同じです。
詳細は Enumerable#sort_by を参照してください。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.minmax_by {|x| x.length } #=> ["dog", "albatross"]

[].minmax_by{} # => [nil, nil]...

絞り込み条件を変える

Enumerable#minmax_by {|obj| ... } -> [object, object] (12200.0)

Enumerable オブジェクトの各要素をブロックに渡して評価し、その結果を <=> で比較して 最小の要素と最大の要素を要素とするサイズ 2 の配列を返します。

...Enumerable#minmax と Enumerable#minmax_by
違いは sort と sort_by の違いと同じです。
詳細は Enumerable#sort_by を参照してください。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.minmax_by {|x| x.length } #=> ["dog", "albatross"]

[].minmax_by{} # => [nil, nil]...

ruby 1.9 feature (36.0)

ruby 1.9 feature ruby version 1.9.0 は開発版です。 以下にあげる機能は将来削除されたり互換性のない仕様変更がなされるかもしれません。 1.9.1 以降は安定版です。 バグ修正がメインになります。

...((<ruby-dev:25031>))

=== 2004-11-14

: Process.getrlimit(resource) [new]
: Process.setrlimit(resource, cur_limit, max_limit) [new]
: Process::RLIM_INFINITY
: Process::RLIM_SAVED_MAX
: Process::RLIM_SAVED_CUR
: Process::RLIMIT_CORE
: Process::RLIMIT_CPU
: Process::RLIMIT_DATA
: Process::RLIMIT_FSIZE...
...040922.html#p01>))

=== 2004-09-20

: Zlib::GzipReader#readpartial(maxlen[, outbuf]) [lib][new]

追加 ((<ruby-dev:24070>))

=== 2004-09-13

: ripper [new]

追加 ((<ruby-dev:24255>))

=== 2004-08-27

: StringIO#readpartial(maxlen[, outbuf]) [lib][new]

追加。((<ruby-dev:24061>))

=== 2...
...加。((<ruby-core:03195>))

=== 2004-07-14

: Enumerable#max_by [new]
: Enumerable#min_by [new]

ブロックの結果を大小比較し、その最大値、最小値を示す要素を返します。

p [1,2,3,4,5].max_by {|v| -v}
# => ruby 1.9.0 (2004-07-17) [i586-linux]...

NEWS for Ruby 2.2.0 (18.0)

NEWS for Ruby 2.2.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...rable
* 追加: Enumerable#slice_after
* 追加: Enumerable#slice_when
* 拡張: Enumerable#min, Enumerable#min_by, Enumerable#max, Enumerable#max_by
は複数の値を返すためのオプションをサポートしました


* Float
* 追加: Float#next_float
* 追加:...

Ruby用語集 (12.0)

Ruby用語集 A B C D E F G I J M N O R S Y

...ターメソッドでは繰り返したい処理をブロックで与える。
また、Enumerable#sort_by、Enumerable#group_by、
Enumerable#max_by などのように、要素に対する「評価関数」
としてブロックを要求するメソッドもある。
Kernel.#open メソッ...