AlfatArdiansa

Codewars w Sandhika 14

Dec 5th, 2020
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function persistence(num) {
  2.   let i = 0;
  3.   while (num.toString().length > 1) {
  4.     num = num
  5.       .toString()
  6.       .split("")
  7.       .map((char) => parseInt(char))
  8.       .reduce((a, b) => a * b);
  9.     i++;
  10.   }
  11.   return i;
  12. }
  13.  
  14. console.log(persistence(39), 3);
  15. console.log(persistence(4), 0);
  16. console.log(persistence(25), 2);
  17. console.log(persistence(999), 4);
  18.  
Add Comment
Please, Sign In to add comment