Code Lab

Modo entrevista. Temporizador de 5 min, sin pistas y sin autocompletado

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.

Ejemplos

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

Devuelve { min: -2, max: 8 }

minMax([7])

Devuelve { min: 7, max: 7 }

One number is both the min and the max.

Fuente

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

Las pruebas ocultas se ejecutan al enviar