Advertisement
CR7CR7

minMaxARR

Feb 12th, 2022
630
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = [
  2.     "3",
  3.     "4",
  4.     "1",
  5.     "2"
  6. ];
  7.  
  8. let print = this.print || console.log;
  9. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  10.  
  11. let n = +gets();
  12. var sum = 0;
  13. let arr = [] ;
  14.  
  15. for (let i = 0 ; i < n ; ++i)
  16. {
  17.     arr.push( +gets() );
  18. }
  19.  
  20. let max = Math.max.apply(null,arr);
  21. let min = Math.min.apply(null,arr);
  22.  
  23. print(`min=${min.toFixed(2)}`);
  24. print(`max=${max.toFixed(2)}`);
  25.  
  26. for(let i = 0; i < n ; i++)
  27. {
  28. sum = sum + arr[i];
  29. }
  30.  
  31. print(`sum=${sum.toFixed(2)}`);
  32. print(`avg=${(sum/n).toFixed(2)}`);
Advertisement
RAW Paste Data Copied
Advertisement