Advertisement
Guest User

04. Trekking Mania

a guest
Aug 1st, 2020
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     let sum = 0;
  3.     let musala = 0;
  4.     let monbolan = 0;
  5.     let kilimanajdaro = 0;
  6.     let k2 = 0;
  7.     let everest = 0;
  8.  
  9.     for (i = 1; i < arr.length; i++) {
  10.         let arrFromI = Number(arr[i]);
  11.         sum += arrFromI;
  12.         if (arrFromI <= 5) {
  13.             musala += arrFromI;
  14.         } else if (arrFromI <= 12) {
  15.             monbolan += arrFromI;
  16.         } else if (arrFromI <= 25) {
  17.             kilimanajdaro += arrFromI;
  18.         } else if (arrFromI <= 40) {
  19.             k2 += arrFromI;
  20.         } else if (arrFromI >= 41) {
  21.             everest += arrFromI
  22.         }
  23.     }
  24.     console.log(((musala / sum) * 100).toFixed(2) + '%');
  25.     console.log(((monbolan / sum) * 100).toFixed(2) + '%');
  26.     console.log(((kilimanajdaro / sum) * 100).toFixed(2) + '%');
  27.     console.log(((k2 / sum) * 100).toFixed(2) + '%');
  28.     console.log(((everest / sum) * 100).toFixed(2) + '%');
  29. }
  30.  
  31. solve([
  32.     '10',
  33.     '10',
  34.     '5',
  35.     '1',
  36.     '100',
  37.     '12',
  38.     '26',
  39.     '17',
  40.     '37',
  41.     '40',
  42.     '78'
  43. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement