- #1
shivajikobardan
- 674
- 54
- TL;DR Summary
- kata not solved.
I'm solving this kata:
https://www.codewars.com/kata/55bf01e5a717a0d57e0000ec/train/javascript
Here's my code but it is not passing few tests. Why's that?
https://www.codewars.com/kata/55bf01e5a717a0d57e0000ec/train/javascript
JavaScript:
function persistence(n) {
var str = n.toString();
let finalproduct;
if (str.length == 1) {
return 0;
}
do {
finalproduct = sop(str);
str = finalproduct;
str = str.toString();
} while (str.length > 1);
return finalproduct;
}
function sop(str1) {
let product = 1;
for (let i = 0; i < str1.length; i++) {
product = product * Number(str1[i]);
}
return product;
}
persistence(4);
Last edited by a moderator: