Run with the following bash command
ts-node computeJoinPoint.ts
function getDigitsTotal(x: number): number { | |
let total = 0; | |
while (x > 0) { | |
total += x % 10; | |
x = Math.floor(x / 10); | |
} | |
return total; | |
} | |
function computeJoinPoint(s1: number, s2: number): number { | |
let sum1 = s1, | |
sum2 = s2; | |
while (sum1 !== sum2) { | |
sum1 += getDigitsTotal(sum1); | |
sum2 += getDigitsTotal(sum2); | |
} | |
return sum1; | |
} | |
console.log(computeJoinPoint(471, 480)); |