Created
January 16, 2021 10:49
-
-
Save JustAyush/5e8642676582fc77148bc8dc6a2c2abe to your computer and use it in GitHub Desktop.
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 super_digit(n, k) { | |
const p = find_p(n, k); | |
const superDigit = find_super_digit(p); | |
return superDigit; | |
} | |
function find_p(n, k) { | |
let concatString = ""; | |
for (let i = 0; i < k; i++) { | |
concatString = concatString + n.toString(); | |
} | |
return concatString; | |
} | |
function find_super_digit(p) { | |
if (p.length === 1) return +p; | |
let arrayOfDigits = p.split(""); | |
let sum = arrayOfDigits.reduce((total, current) => total + (+current), 0); | |
sum = sum.toString(); | |
return find_super_digit(sum.toString()); | |
} | |
const superDigit = super_digit(148, 3); | |
console.log(superDigit); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment