Find the largest and smallest numbers in an array in JavaScript using Math.max() and Math.min().

  • Here, spread operator converts an array into individual arguments.
  • So Math.max and Math.min expect a list of arguments, not an array directly.
  • For small and medium size arrays Math.max and Math.min are the simplest and most effective way.
  • For Large Arrays we need to use Array.reduce() for better performance.
  • And most importantly Math.max and Math.min works only for array of numbers.

Leave a comment