Monday, December 20, 2010

Finding Max and Min values in an Array

To Find the min and max of an array, there is a simple technique by making use of javascript apply method which takes this object and an array of arguments.

To find the Max of an array
Math.max.apply(Math, [1,2,3,4,5,6,7,8]);

To find the min of an array
Math.min.apply(Math, [1,2,3,4,5,6,7,8]);

No comments: