るりまサーチ

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

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method new
  4. irb/input-method gets
  5. matrix -

ライブラリ

モジュール

キーワード

検索結果

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

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

...erable#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)...
...06)
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 is 20000 samples from e.
p a.length #=> 20000
h = a.group_by {|x| x }
-
10.upto(10) {|x| puts "*" * (h[x].length/30.0)...

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

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

...erable#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)...
...06)
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 is 20000 samples from e.
p a.length #=> 20000
h = a.group_by {|x| x }
-
10.upto(10) {|x| puts "*" * (h[x].length/30.0)...

Enumerable#max_by -> Enumerator (18309.0)

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

...erable#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)...
...06)
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 is 20000 samples from e.
p a.length #=> 20000
h = a.group_by {|x| x }
-
10.upto(10) {|x| puts "*" * (h[x].length/30.0)...

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

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

...erable#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)...
...06)
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 is 20000 samples from e.
p a.length #=> 20000
h = a.group_by {|x| x }
-
10.upto(10) {|x| puts "*" * (h[x].length/30.0)...

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

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

...le#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 -> Enumerator (6207.0)

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

...le#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 (1992.0)

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

...w]: 追加されたクラス/メソッドなど
* [compat]: 変更されたクラス/メソッドなど(互換性のある変更) (only backward-compatibility) (影響の範囲が小さいと思われる変更もこちら)
* [change]: 変更されたクラス/メソッドなど(互換性...
...((<ruby-list:40865>))

=== 2005-06-08
: Array#nitems [compat]

Array#nitems にブロックを渡せるようになり、ブロックが真になる要素の個数を返すように
なりました。

[1,2,3].nitems{|i| i % 2 != 0} #=> 2

((<ruby-talk:134083>))

=== 2005-06-02
: proc...
...tch("foobar", 4).offset(0))
# => ruby 1.9.0 (2004-07-17) [i586-linux]
[4, 5]

=== 2004-07-16

: File::Stat#dev_major [new]
: File::Stat#dev_minor [new]

追加。((<ruby-core:03195>))

=== 2004-07-14

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

ブロック...

Ruby用語集 (144.0)

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

...l#percent

: 0 オリジン
: zero-based
番号が 0 から始まること。

例えば、
Array や Vector、Matrix などの要素の番号、
String における文字の位置、
といったものは 0 オリジンである。

: 1 オリジン
: one-based
番号が 1 から始ま...
...「==」のような
関係演算子は、メソッド呼び出しの構文糖衣であり、再定義もできる。
「x and y」「x || y」の and や || はメソッド呼び出しとは関係が
なく、再定義もできない。
代入式「n = 1」における「=」は代入演算...
...ターメソッドでは繰り返したい処理をブロックで与える。
また、Enumerable#sort_by、Enumerable#group_by、
Enumerable#max_by などのように、要素に対する「評価関数」
としてブロックを要求するメソッドもある。
Kernel.#open メソッ...