Find minimum and maximum of an array

Given an array of numbers, find the minimum and maximum elements by scanning the array once.

Hint

Set the smallest number (min) to the largest possible value (infinity). Set the largest number (max) to the smallest possible value (negative infinity). Go through each number in the list.

Return: After checking all numbers in the list, return the values of min and max.

# Python implementation
ls = [1, 2, 3, 4, 5, 6, 7, 8, 9]

mn = float('inf')
mx = float('-inf')

for item in ls:
  mn = min(mn, item)
  mx = max(mx, item)

print((mn, mx))
// Javascript implementation
const list = [1, 2, 3, 4, 5, 6, 7, 8, 9];

let min = Infinity;
let max = -Infinity;

for (let item of list) {
  min = Math.min(min, item);
  max = Math.max(max, item);
}

console.log({ min: min, max: max });