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

by webdood on Feb.25, 2009, under Javascript, Software Development

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

:, ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!


A few highly recommended websites...

  • A List Apart
  • Dive into HTML5
  • Javascript: The Good Parts
  • QuirksMode.org