TZinovieva

Number Modification JS Fundamentals

Feb 5th, 2023
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function numberModification(num) {
  2.     let digits = num.toString().split('');
  3.     let average = 0;
  4.     while (average <= 5) {
  5.         average = 0;
  6.         for (let i = 0; i < digits.length; i++) {
  7.             average += parseInt(digits[i]);
  8.         }
  9.         average /= digits.length;
  10.         if (average <= 5) {
  11.             num = parseInt(num + "9");
  12.             digits = num.toString().split('');
  13.         }
  14.     }
  15.     console.log(num);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment