Taken from DailyCodingProblem
A number is considered perfect if its digits sum to exactly
10
.Given a positive integer
n
, return then
-th perfect number.For exmaple, given
1
, you should return19
. Given2
, you should return28
.
Solution
This is the answer I came up with:
function perfect(n: number): number {
let digits = [n, 0]
while (digits[0] + digits[1] !== 10) {
digits[1]++
}
return Number(digits.join(''))
}