Created
August 7, 2017 05:44
-
-
Save kenjinp/846bb657eef1cb0b018cddd536d691bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns if the number is dense or not (averge of digits > 7) | |
* @param {int} int to test | |
* @returns {boolean} | |
*/ | |
function isDenseNumber(int) { | |
let digitArray = [] | |
let valDigits = 0 | |
while (int) { | |
let digit = int % 10 | |
digitArray.push(digit) | |
valDigits += digit | |
int = parseInt(int / 10) | |
} | |
digitArray.reverse() | |
let isDense = (valDigits / digitArray.length) > 7 | |
return isDense | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment