Saturday, April 4, 2009

Min/Max

SQL contains a number of aggregate functions that can do things like select the largest or smallest number from a set of values. This could be handy in the programming language itself.


ASP

  1. function max(arrNumbers)
  2.     dim result
  3.     result = arrNumbers(0)
  4.     for each i in arrNumbers
  5.         if i > result then
  6.             result = i
  7.         end if
  8.     next
  9.     max = result
  10. end function
  11. function min(arrNumbers)
  12.     dim result
  13.     result = arrNumbers(0)
  14.     for each i in arrNumbers
  15.         if i < result then
  16.             result = i
  17.         end if
  18.     next
  19.     min = result
  20. end function

View ASP implementation on Snipplr

No comments: