Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function footballLeague(input) {
- let stadiumCapacity = Number(input[0]);
- let footballFans = Number(input[1]);
- let sectorA = 0;
- let sectorB = 0;
- let sectorV = 0;
- let sectorG = 0;
- for (let i = 2; i < footballFans + 2; i++){
- if (input[i] === "A"){
- sectorA++;
- } else if (input[i] === "B"){
- sectorB++;
- } else if (input[i] === "V"){
- sectorV++;
- } else if (input[i] === "G"){
- sectorG++;
- }
- }
- console.log(`${(sectorA / footballFans * 100).toFixed(2)}%`);
- console.log(`${(sectorB / footballFans * 100).toFixed(2)}%`);
- console.log(`${(sectorV / footballFans * 100).toFixed(2)}%`);
- console.log(`${(sectorG / footballFans * 100).toFixed(2)}%`);
- console.log(`${(footballFans / stadiumCapacity * 100).toFixed(2)}%`);
- }
- Фундаменталс решение:
- function footballLeague(input) {
- let stadiumCapacity = Number(input.shift());
- let footballFans = Number(input.shift());
- let sectors = { 'A': 0, 'B': 0, 'V': 0, 'G': 0 };
- input.forEach(s => { sectors[s]++; });
- for (const s in sectors) {
- console.log(`${(sectors[s] / footballFans * 100).toFixed(2)}%`);
- }
- console.log(`${(footballFans / stadiumCapacity * 100).toFixed(2)}%`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement