MMCT TEAM
Server IP : 111.118.215.189  /  Your IP : 216.73.216.153
Web Server : Apache
System : Linux md-in-83.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : a1673wkz ( 2475)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /proc/thread-self/root/opt/cpanel/ea-ruby24/root/usr/share/ri/system/Enumerable/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //proc/thread-self/root/opt/cpanel/ea-ruby24/root/usr/share/ri/system/Enumerable/max_by-i.ri
U:RDoc::AnyMethod[iI"max_by:ETI"Enumerable#max_by;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph;	[I">Returns the object in <i>enum</i> that gives the maximum ;TI" value from the given block.;To:RDoc::Markup::BlankLineo;
;	[I"=If no block is given, an enumerator is returned instead.;T@o:RDoc::Markup::Verbatim;	[I"!a = %w(albatross dog horse)
;TI"1a.max_by { |x| x.length }   #=> "albatross"
;T:@format0o;
;	[I"EIf the +n+ argument is given, maximum +n+ elements are returned ;TI"Fas an array. These +n+ elements are sorted by the value from the ;TI"&given block, in descending order.;T@o;;	[I"!a = %w[albatross dog horse]
;TI"<a.max_by(2) {|x| x.length } #=> ["albatross", "horse"]
;T;
0o;
;	[I"Genum.max_by(n) can be used to implement weighted random sampling. ;TI"=Following example implements and use Enumerable#wsample.;T@o;;	[-I"module Enumerable
;TI"#  # weighted random sampling.
;TI"	  #
;TI"0  # Pavlos S. Efraimidis, Paul G. Spirakis
;TI"3  # Weighted random sampling with a reservoir
;TI"(  # Information Processing Letters
;TI",  # Volume 97, Issue 5 (16 March 2006)
;TI"  def wsample(n)
;TI"6    self.max_by(n) {|v| rand ** (1.0/yield(v)) }
;TI"  end
;TI"	end
;TI"e = (-20..20).to_a*10000
;TI"a = e.wsample(20000) {|x|
;TI"3  Math.exp(-(x/5.0)**2) # normal distribution
;TI"}
;TI""# a is 20000 samples from e.
;TI"p a.length #=> 20000
;TI"h = a.group_by {|x| x }
;TI"D-10.upto(10) {|x| puts "*" * (h[x].length/30.0).to_i if h[x] }
;TI"#=> *
;TI"
#   ***
;TI"#   ******
;TI"#   ***********
;TI"#   ******************
;TI"'#   *****************************
;TI"3#   *****************************************
;TI">#   ****************************************************
;TI"I#   ***************************************************************
;TI"N#   ********************************************************************
;TI"Q#   ***********************************************************************
;TI"Q#   ***********************************************************************
;TI"H#   **************************************************************
;TI">#   ****************************************************
;TI"1#   ***************************************
;TI"%#   ***************************
;TI"#   ******************
;TI"#   ***********
;TI"#   *******
;TI"
#   ***
;TI"
#   *;T;
0:
@fileI"enum.c;T:0@omit_headings_from_table_of_contents_below0I"�enum.max_by {|obj| block }      -> obj
enum.max_by                     -> an_enumerator
enum.max_by(n) {|obj| block }   -> obj
enum.max_by(n)                  -> an_enumerator
;T0[I"(p1 = v1);T@NFI"Enumerable;TcRDoc::NormalModule00

MMCT - 2023