Advertisement
CR7CR7

MinMax

Feb 11th, 2022
1,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Input.
  2. let input = [3, 2, 5, 1];
  3.  
  4. // Custom implementation of read and print. Do not touch : )
  5. let print = this.print || console.log;
  6. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  7.  
  8. // Solution
  9.  
  10. let num = +gets();
  11. let max = Number.MIN_SAFE_INTEGER;
  12. let min = Number.MAX_SAFE_INTEGER;
  13. let total = 0;
  14. for (i = 1; i <= num; i++) {
  15.     let newValue = +gets();
  16.     if (newValue >= max) {
  17.         max = newValue;
  18.     }
  19.     if (newValue <= min) {
  20.         min = newValue;
  21.     }
  22.     total += newValue;
  23. }
  24. print(`min=${min.toFixed(2)}`);
  25. print(`max=${max.toFixed(2)}`);
  26. print(`sum=${total.toFixed(2)}`);
  27. print(`avg=${(total / num).toFixed(2)}`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement