# All files / algorithms/lib minMaxNumber.ts

0% Statements 0/28
0% Branches 0/1
0% Functions 0/1
0% Lines 0/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53

     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);