There is a code that accepts an array and must return a sorted array of two elements, the first is the smallest, the second is the largest value in the transmitted array. Logically did everything right, but I don’t make the code work. Help me to understand.
function minMax(arr){ function determineOrder(num){ return (num[0] > num[1]) ? array.push(num[0], num[1]) : array.push(num[1], num[0]) ; } return arr.map(determineOrder); } minMaxminMax([1,2,3,4,5]) ; And I expected this result:
minMax([1,2,3,4,5]) == [1,5] minMax([2334454,5]) == [5, 2334454] minMax([1]) == [1, 1]
minMaxminMax([1,2,3,4,5]) ;- Grundyconst minmax = (a, m = Math) => [m.min(...a), m.max(...a)];With the tip of Grundy - saaaaaaaaasha