Task

Create a function that returns the maximum value in a provided set of values,

where the number of values may not be known until run-time.




/* NetRexx */
 
options replace format comments java crossref savelog symbols binary
 
rn = Random()
maxElmts = 100
dlist = double[maxElmts]
rlist = Rexx[maxElmts]
loop r_ = 0 to maxElmts - 1
  nr = rn.nextGaussian * 100.0
  dlist[r_] = nr
  rlist[r_] = Rexx(nr)
  end r_
 
say 'Max double:' Rexx(getMax(dlist)).format(4, 9)
say 'Max   Rexx:' getMax(rlist).format(4, 9)
 
return
 
method getMax(dlist = double[]) public static binary returns double
  dmax = Double.MIN_VALUE
  loop n_ = 0 to dlist.length - 1
    if dlist[n_] > dmax then dmax = dlist[n_]
    end n_
  return dmax
 
method getMax(dlist = Rexx[]) public static binary returns Rexx
  dmax = Rexx(Double.MIN_VALUE)
  loop n_ = 0 to dlist.length - 1
    dmax = dlist[n_].max(dmax)
    end n_
  return dmax
 