Code Lab

Mode entretien. Minuteur de 5 min, sans indices ni autocomplétion

Min and max

FacileArrays5 min

Write a function minMax(numbers) that returns an object { min, max } with the smallest and the largest number of an array. The array is not empty. Do not use Math.min or Math.max.

Exemples

minMax([3, -2, 8, 0])

Renvoie { min: -2, max: 8 }

minMax([7])

Renvoie { min: 7, max: 7 }

One number is both the min and the max.

Source

Chargement de l'éditeur...
  1. EntréeminMax([ 3, -2, 8, 0 ])
    Attendu{ min: -2, max: 8 }
  2. EntréeminMax([ 7 ])
    Attendu{ min: 7, max: 7 }

Les tests cachés se lancent à la soumission