TZinovieva

Division Without Remainder JS

Dec 5th, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function divisionWithoutRemainder(input) {
  2.     let n = Number(input[0]);
  3.     let index = 1;
  4.  
  5.     let divisibleBy2 = 0;
  6.     let divisibleBy3 = 0;
  7.     let divisibleBy4 = 0;
  8.  
  9.     for (let i = 1; i <= n; i++) {
  10.         let currentNumber = Number(input[index]);
  11.         index++;
  12.         if (currentNumber % 2 === 0) {
  13.             divisibleBy2++;
  14.         }
  15.         if (currentNumber % 3 === 0) {
  16.             divisibleBy3++;
  17.         }
  18.         if (currentNumber % 4 === 0) {
  19.             divisibleBy4++;
  20.         }
  21.     }
  22.     console.log(`${(divisibleBy2 / n * 100).toFixed(2)}%`);
  23.     console.log(`${(divisibleBy3 / n * 100).toFixed(2)}%`);
  24.     console.log(`${(divisibleBy4 / n * 100).toFixed(2)}%`);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment