Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Histogram(input) {
- let count = Number(input[0]);
- let p1 = 0;
- let p2 = 0;
- let p3 = 0;
- let p4 = 0;
- let p5 = 0;
- for (let i = 1; i <= count; i++) {
- let number = Number(input[i]);
- if (number < 200) {
- p1 += 1;
- } else if (number < 400) {
- p2 += 1;
- } else if (number < 600) {
- p3 += 1;
- } else if (number < 800) {
- p4 += 1;
- } else {
- p5 += 1;
- }
- }
- console.log(`${(p1 / count * 100).toFixed(2)}%`);
- console.log(`${(p2 / count * 100).toFixed(2)}%`);
- console.log(`${(p3 / count * 100).toFixed(2)}%`);
- console.log(`${(p4 / count * 100).toFixed(2)}%`);
- console.log(`${(p5 / count * 100).toFixed(2)}%`);
- }
- Тарикатско решение:)
- function Histogram(input) {
- let num = Number(input.shift());
- let histogram = [0, 0, 0, 0, 0];
- for (let i = 0; i < num; i++) {
- let n = Number(input.shift());
- histogram[(n < 200 ? 0 : n < 400 ? 1 : n < 600 ? 2 : n < 800 ? 3 : 4)]++;
- }
- for (let h of histogram) {
- console.log(`${(h / num * 100).toFixed(2)}%`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement