Created
April 8, 2021 10:06
-
-
Save joshfarrant/feb47830052d2aefbfaf6d1e470b021b to your computer and use it in GitHub Desktop.
Code Kata Solutions - Persistent Bugger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const multiply = (a, b) => a * b; | |
const multiplyDigits = num => ( | |
String(num).split('').reduce(multiply) | |
); | |
const persistence = (num, count = 0) => { | |
if (num < 10) { | |
return count; | |
} | |
const multiplied = multiplyDigits(num); | |
return persistence(multiplied, count + 1); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const multiply = (a, b) => a * b; | |
const multiplyDigits = num => ( | |
String(num).split('').reduce(multiply) | |
); | |
const persistence = num => { | |
let count = 0; | |
while (num > 9) { | |
count += 1; | |
num = multiplyDigits(num); | |
} | |
return count; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment