MartenBG

Untitled

Feb 11th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function histogram(input) {
  2. let n = +(input.shift());
  3. let p1 = 0;
  4. let p2 = 0;
  5. let p3 = 0;
  6. let p4 = 0;
  7. let p5 = 0;
  8. let n1 =0;
  9. let n2 =0;
  10. let n3 =0;
  11. let n4 =0;
  12. let n5 =0;
  13.  
  14. for (let i = 0; i < n; i++) {
  15. num = +(input[i]);
  16. if (num < 200) {
  17. p1++;
  18. } else if (num <= 399) {
  19. p2++;
  20. } else if (num >= 400 && num <= 599) {
  21. p3++;
  22. } else if (num >= 600 && num <= 799) {
  23. p4++;
  24. } else if (num >= 800) {
  25. p5++;
  26. }
  27. }
  28. console.log(`${(n1 = p1/n * 100).toFixed(2)}%`);
  29. console.log(`${(n2 = p2/n * 100).toFixed(2)}%`);
  30. console.log(`${(n3 = p3/n * 100).toFixed(2)}%`);
  31. console.log(`${(n4 = p4/n * 100).toFixed(2)}%`);
  32. console.log(`${(n5 = p5/n * 100).toFixed(2)}%`);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment