Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function histogram(input) {
- let n = +(input.shift());
- let p1 = 0;
- let p2 = 0;
- let p3 = 0;
- let p4 = 0;
- let p5 = 0;
- let n1 =0;
- let n2 =0;
- let n3 =0;
- let n4 =0;
- let n5 =0;
- for (let i = 0; i < n; i++) {
- num = +(input[i]);
- if (num < 200) {
- p1++;
- } else if (num <= 399) {
- p2++;
- } else if (num >= 400 && num <= 599) {
- p3++;
- } else if (num >= 600 && num <= 799) {
- p4++;
- } else if (num >= 800) {
- p5++;
- }
- }
- console.log(`${(n1 = p1/n * 100).toFixed(2)}%`);
- console.log(`${(n2 = p2/n * 100).toFixed(2)}%`);
- console.log(`${(n3 = p3/n * 100).toFixed(2)}%`);
- console.log(`${(n4 = p4/n * 100).toFixed(2)}%`);
- console.log(`${(n5 = p5/n * 100).toFixed(2)}%`);
- }
Advertisement
Add Comment
Please, Sign In to add comment