Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function persistence(num) {
- let i = 0;
- while (num.toString().length > 1) {
- num = num
- .toString()
- .split("")
- .map((char) => parseInt(char))
- .reduce((a, b) => a * b);
- i++;
- }
- return i;
- }
- console.log(persistence(39), 3);
- console.log(persistence(4), 0);
- console.log(persistence(25), 2);
- console.log(persistence(999), 4);
Add Comment
Please, Sign In to add comment