'Array excersize in Javascript [closed]

I have a function that receives as an argument an array of numbers called 'numbers' and must return an array containing the smallest number in the 'numbers' array at position zero and the largest number in the array 'numbers' in position 1.

  maxValue = Math.max(numbers)
  minValue = Math.min(numbers)
  varResult = ([minValue, maxValue]);

  for (let i = 0; i < numbers.length; i++) {
  console.log (varResult);
  } 
} ```


Solution 1:[1]

You can not pass an array to Math.min or Math.max.
You'll need to spread the numbers, like:

maxValue = Math.max(...numbers)
minValue = Math.min(...numbers)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CD..