Skip to content

Instantly share code, notes, and snippets.

@Ge0rg3
Created June 7, 2018 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ge0rg3/78880e389445691e9869c650d8515227 to your computer and use it in GitHub Desktop.
Save Ge0rg3/78880e389445691e9869c650d8515227 to your computer and use it in GitHub Desktop.
Finds a number's multiplicative persistence.
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