Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gameOfIntervals(input) {
- let num = Number(input[0]);
- let result = 0.00;
- let num0To10 = 0;
- let num10To20 = 0;
- let num20To30 = 0;
- let num30To40 = 0;
- let num40To50 = 0;
- let numInvalid = 0;
- for (let i = 1; i <= num; i++) {
- let number = Number(input[i]);
- if (number >= 0 && number < 10) {
- result += number * 0.2;
- num0To10++;
- } else if (number >= 10 && number < 20) {
- result += number * 0.3;
- num10To20++;
- } else if (number >= 20 && number < 30) {
- result += number * 0.4;
- num20To30++;
- } else if (number >= 30 && number < 40) {
- result += 50;
- num30To40++;
- } else if (number >= 40 && number <= 50) {
- result += 100;
- num40To50++;
- } else{
- result /= 2;
- numInvalid++;
- }
- }
- console.log(`${result.toFixed(2)}`);
- console.log(`From 0 to 9: ${(num0To10 / num * 100).toFixed(2)}%`);
- console.log(`From 10 to 19: ${(num10To20 / num * 100).toFixed(2)}%`);
- console.log(`From 20 to 29: ${(num20To30 / num * 100).toFixed(2)}%`);
- console.log(`From 30 to 39: ${(num30To40 / num * 100).toFixed(2)}%`);
- console.log(`From 40 to 50: ${(num40To50 / num * 100).toFixed(2)}%`);
- console.log(`Invalid numbers: ${(numInvalid / num * 100).toFixed(2)}%`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement