export const min = (list: number[]): number => {
  list.sort();
  let L = 0;
  let R = list.length - 1;
  let res = list[L];

  while (L <= R) {
    res = Math.min(list[L], list[R], res);

    L++;
    R--;
  }

  return res;
};

export const max = (list: number[]): number => {
  list.sort();
  let L = 0;
  let R = list.length - 1;
  let res = list[L];

  while (L <= R) {
    res = Math.max(list[L], list[R], res);

    L++;
    R--;
  }

  return res;
};

// const min = (list) => Math.min(...list);
// const max = (list) => Math.max(...list);

// export const min = (list: number[]): number => {
//   return list.sort((leftvalue, rightvalue): number => {
//     return leftvalue - rightvalue;
//   })[0];
// };

// export const max = (list: number[]): number => {
//   return list.sort((leftvalue, rightvalue): number => {
//     return leftvalue - rightvalue;
//   })[list.length - 1];
// };

console.log(min([-52, 56, 30, 29, -54, 0, -110]), -110);
console.log(min([42, 54, 65, 87, 0]), 0);

console.log(max([4, 6, 2, 1, 9, 63, -134, 566]), 566);
console.log(max([5]), 5);
