Posted By

Scooter on 04/04/09


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

nelda751
benrudolph
asifrizvigmailcom


Min/Max


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2009/04/minmax.html

Select the largest or smallest value from an array of integers.

  1. <%
  2. ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' Returns the numerically highest value from a given array.
  10. function max(arrNumbers)
  11. dim result
  12.  
  13. result = arrNumbers(0)
  14.  
  15. for each i in arrNumbers
  16. if i > result then
  17. result = i
  18. end if
  19. next
  20.  
  21. max = result
  22. end function
  23.  
  24. ' Returns the numerically lowest value from a given array.
  25. function min(arrNumbers)
  26. dim result
  27.  
  28. result = arrNumbers(0)
  29.  
  30. for each i in arrNumbers
  31. if i < result then
  32. result = i
  33. end if
  34. next
  35.  
  36. min = result
  37. end function
  38. %>

Report this snippet  

You need to login to post a comment.