Advertisement
CR7CR7

trackingM

Feb 2nd, 2024
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function trekkingMania(input) {
  2.     let groupsQty = Number(input[0]);
  3.  
  4.     let groupMusala = 0;
  5.     let groupMontblank = 0;
  6.     let groupKilimanjaro = 0;
  7.     let groupK2 = 0;
  8.     let groupEverest = 0;
  9.     let totalPeople = 0;
  10.  
  11.     for (let i = 1; i < input.length; i++) {
  12.         let group = Number(input[i]);
  13.         totalPeople += group;
  14.  
  15.         if (group <= 5) {
  16.             groupMusala += group;
  17.         } else if (group <= 12) {
  18.             groupMontblank += group;
  19.         } else if (group <= 25) {
  20.             groupKilimanjaro += group;
  21.         } else if (group >= 26 && group <= 40) {
  22.             groupK2 += group;
  23.         } else {
  24.             groupEverest += group;
  25.         }
  26.     }
  27.  
  28.     let percentMusala = (groupMusala / totalPeople) * 100;
  29.     let percentMontblanc = (groupMontblank / totalPeople) * 100;
  30.     let percentKilimanjaro = (groupKilimanjaro / totalPeople) * 100;
  31.     let percentK2 = (groupK2 / totalPeople) * 100;
  32.     let percentEverest = (groupEverest / totalPeople) * 100;
  33.  
  34.     console.log(percentMusala.toFixed(2) + "%");
  35.     console.log(percentMontblanc.toFixed(2) + "%");
  36.     console.log(percentKilimanjaro.toFixed(2) + "%");
  37.     console.log(percentK2.toFixed(2) + "%");
  38.     console.log(percentEverest.toFixed(2) + "%");
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement