We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7ba5e47 commit 41d2b07Copy full SHA for 41d2b07
6kyus/js/persistentBugger.js
@@ -7,12 +7,20 @@
7
function persistence(num) {
8
// pseudocode:
9
// create counter
10
- // create a while loop that only runs when num is less than 10
+ // create a while loop that only runs until num is less than 10
11
// convert num to string
12
// string to array
13
// reduce to new num
14
// 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
23
}
24
25
console.log(persistence(39), 3)
-console.log(persistence(999), 4)
26
+// console.log(persistence(999), 4)
0 commit comments