Advertisement
ErolKZ

Untitled

Jul 10th, 2021
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. function solve(input) {
  2.  
  3.  
  4. let countNumbers = Number(input[0]);
  5.  
  6. let p1 = 0;
  7.  
  8. let p2 = 0;
  9.  
  10. let p3 = 0;
  11.  
  12.  
  13.  
  14. for (let i = 1; i <= countNumbers; i++) {
  15.  
  16.  
  17. if (input[i] % 2 === 0) {
  18.  
  19. p1 += 1;
  20.  
  21. }
  22.  
  23.  
  24. if (input[i] % 3 === 0) {
  25.  
  26. p2 += 1;
  27.  
  28. }
  29.  
  30.  
  31. if (input[i] % 4 === 0) {
  32.  
  33. p3 += 1;
  34.  
  35. }
  36.  
  37.  
  38. }
  39.  
  40.  
  41. p1 = p1 / countNumbers * 100;
  42. p2 = p2 / countNumbers * 100;
  43. p3 = p3 / countNumbers * 100;
  44.  
  45.  
  46.  
  47.  
  48.  
  49. console.log(`${p1.toFixed(2)}%`);
  50. console.log(`${p2.toFixed(2)}%`);
  51. console.log(`${p3.toFixed(2)}%`);
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement