Code Lab

Modo entrevista. Cronômetro de 5 min, sem dicas e sem autocompletar

Min and max

FácilArrays5 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.

Exemplos

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

Retorna { min: -2, max: 8 }

minMax([7])

Retorna { min: 7, max: 7 }

One number is both the min and the max.

Fonte

Carregando o editor...
  1. EntradaminMax([ 3, -2, 8, 0 ])
    Esperado{ min: -2, max: 8 }
  2. EntradaminMax([ 7 ])
    Esperado{ min: 7, max: 7 }

Os testes ocultos rodam no envio