Skip to content

Instantly share code, notes, and snippets.

@joshfarrant
Created April 8, 2021 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfarrant/feb47830052d2aefbfaf6d1e470b021b to your computer and use it in GitHub Desktop.
Save joshfarrant/feb47830052d2aefbfaf6d1e470b021b to your computer and use it in GitHub Desktop.
Code Kata Solutions - Persistent Bugger
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);
};
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