Skip to content

Commit 41d2b07

Browse files
complete persistence while loop
1 parent 7ba5e47 commit 41d2b07

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

6kyus/js/persistentBugger.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77
function persistence(num) {
88
// pseudocode:
99
// create counter
10-
// create a while loop that only runs when num is less than 10
10+
// create a while loop that only runs until num is less than 10
1111
// convert num to string
1212
// string to array
1313
// reduce to new num
1414
// return num
15+
let counter = 0
16+
while (num > 9) {
17+
num = String(num)
18+
.split('')
19+
.reduce((acc, curr) => acc * curr)
20+
counter++
21+
}
22+
return counter
1523
}
1624

1725
console.log(persistence(39), 3)
18-
console.log(persistence(999), 4)
26+
// console.log(persistence(999), 4)

0 commit comments

Comments
 (0)