Created
June 7, 2018 22:37
-
-
Save Ge0rg3/78880e389445691e9869c650d8515227 to your computer and use it in GitHub Desktop.
Finds a number's multiplicative persistence.
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
function persistence(num) { | |
let stringnum = num.toString() | |
let count = 0; | |
while ((stringnum).length > 1) { | |
count++; | |
let nums = stringnum.split(""); | |
let m = 1; | |
for (let i = 0; i < nums.length; i++) { | |
m = m*nums[i]; | |
} | |
stringnum = m.toString(); | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment