Last active
August 24, 2021 02:00
-
-
Save nkgokul/4a4f4a63ba8cd74b5097256bb9694346 to your computer and use it in GitHub Desktop.
Persistence of a number
This file contains hidden or 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
function digit_product(number) { | |
let digit_product = 1; | |
while (number) { | |
digit_product *= number % 10; | |
number = Math.floor(number / 10); | |
} | |
return digit_product; | |
} | |
function persistence(number) { | |
if (number < 10) return 0; | |
return persistence(digit_product(number)) + 1; | |
} | |
find = 1; | |
while (persistence(find) < 5) { | |
find++; | |
} | |
console.log(find); | |
test_input_array = [10, 25, 39, 77]; | |
test_input_array.map(number => console.log(number + " " + persistence(number))); | |
// console.log(persistence(999)) | |
// console.log(find + " " + persistence(find)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment