Advertisement
Spocoman

07. Football League

Dec 26th, 2021 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function footballLeague(input) {
  2.     let stadiumCapacity = Number(input[0]);
  3.     let footballFans = Number(input[1]);
  4.     let sectorA = 0;
  5.     let sectorB = 0;
  6.     let sectorV = 0;
  7.     let sectorG = 0;
  8.  
  9.     for (let i = 2; i < footballFans + 2; i++){
  10.         if (input[i] === "A"){
  11.             sectorA++;
  12.         } else if (input[i] === "B"){
  13.             sectorB++;
  14.         } else if (input[i] === "V"){
  15.             sectorV++;
  16.         } else if (input[i] === "G"){
  17.             sectorG++;
  18.         }
  19.     }
  20.  
  21.     console.log(`${(sectorA / footballFans * 100).toFixed(2)}%`);
  22.     console.log(`${(sectorB / footballFans * 100).toFixed(2)}%`);
  23.     console.log(`${(sectorV / footballFans * 100).toFixed(2)}%`);
  24.     console.log(`${(sectorG / footballFans * 100).toFixed(2)}%`);
  25.     console.log(`${(footballFans / stadiumCapacity * 100).toFixed(2)}%`);
  26. }
  27.  
  28. Фундаменталс решение:
  29.  
  30. function footballLeague(input) {
  31.     let stadiumCapacity = Number(input.shift());
  32.     let footballFans = Number(input.shift());
  33.  
  34.     let sectors = { 'A': 0, 'B': 0, 'V': 0, 'G': 0 };
  35.  
  36.     input.forEach(s => { sectors[s]++; });
  37.  
  38.     for (const s in sectors) {
  39.         console.log(`${(sectors[s] / footballFans * 100).toFixed(2)}%`);
  40.     }
  41.     console.log(`${(footballFans / stadiumCapacity * 100).toFixed(2)}%`);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement