skip to main | skip to sidebar

Shannon Norrell Webdood Tech

Wednesday, February 25, 2009

Fast JavaScript Max/Min on an Array Taking Arbitrary Number of Arguments

What's the fastest way to find the largest, or smallest, number in an array?

Array.max = function( array ){
return Math.max.apply( Math, array );
};
Array.min = function( array ){
return Math.min.apply( Math, array );
};

By using JavaScript's .apply() method on a built-in function you can pass in an array of unlimited arguments.

Shannon Norrell

Posted by WebDood at 2:59 PM No comments:
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Blog Archive

  • ►  2026 (1)
    • ►  April (1)
  • ►  2014 (1)
    • ►  May (1)
  • ►  2012 (2)
    • ►  July (1)
    • ►  June (1)
  • ►  2011 (3)
    • ►  August (1)
    • ►  March (1)
    • ►  January (1)
  • ►  2010 (8)
    • ►  October (1)
    • ►  September (1)
    • ►  August (2)
    • ►  June (1)
    • ►  April (2)
    • ►  March (1)
  • ▼  2009 (8)
    • ►  December (1)
    • ►  October (1)
    • ►  September (2)
    • ►  July (1)
    • ►  May (1)
    • ►  April (1)
    • ▼  February (1)
      • Fast JavaScript Max/Min on an Array Taking Arbitra...
  • ►  2008 (3)
    • ►  September (1)
    • ►  March (2)
  • ►  2007 (20)
    • ►  December (1)
    • ►  October (1)
    • ►  September (5)
    • ►  August (1)
    • ►  July (1)
    • ►  June (8)
    • ►  May (3)

About Me

WebDood
View my complete profile