dabidabidesh

Number Modification

Jun 16th, 2020
320
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //15 EXERCISE: FUNCTIONS/More Exercise/02. Number Modification.js
  2. function numberModification(num) {
  3.   'use strict'
  4.  
  5.   let str = String(num)
  6.  
  7.   const isAverageValueHigherThan5 = str => {
  8.  
  9.     let sum = 0
  10.     let i
  11.  
  12.     for (i = 0; i < str.length; i++)
  13.       sum += +str[i]
  14.  
  15.     let average = sum / i
  16.     if (average > 5)
  17.       return true
  18.     else
  19.       return false
  20.   }
  21.  
  22.   while (!isAverageValueHigherThan5(str)) {
  23.     str += '9'
  24.   }
  25.  
  26.   console.log(str)
  27. }
RAW Paste Data