Code Lab

Min and max

EasyArrays5 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.

Examples

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

Returns { min: -2, max: 8 }

minMax([7])

Returns { min: 7, max: 7 }

One number is both the min and the max.

Source

Loading the editor...
  1. InputminMax([ 3, -2, 8, 0 ])
    Expected{ min: -2, max: 8 }
  2. InputminMax([ 7 ])
    Expected{ min: 7, max: 7 }

Hidden tests run on Submit.