Your challenge is to, given a positive integer n, count up to each digit of it, giving the effect of converging on it.
Basically, count up to the first digit of n by its place value (\$⌊\log_{10}\left(x\right)⌋\$). Then do the same for each subsequent digit, but with the values of the previous digits added.
Example implementation (animated):
function count(){
let countTo = document.getElementById('number').value.toString().split``,output = document.getElementById('x');
let numbers = [], accumulator = 0;
countTo.map((value, index) => {
for(let i = 0; i < +value; i++){
accumulator += 10 ** (countTo.length - index - 1)
numbers.push(accumulator)
}
});
//document.getElementById('y').innerHTML = 'All values:<br>' + numbers.join`<br>`;
(function next(){let nextVal = numbers.shift();if(nextVal){output.innerHTML = nextVal;setTimeout(next,300)}})()
}
p{font-family:monospace}
<label for=number>Number: </label><input id=number type=number> <button onclick=count()>Count!</button><p id=x></p><p id=y></p>
You should just return an array of numbers - for n=47:
10
20
30
40
41
42
43
44
45
46
47
You may optionally have leading zeroes. IO may be strings, numbers, digit lists, etc.
Testcases:
4 => [1, 2, 3, 4]
16 => [10, 11, 12, 13, 14, 15, 16]
35 => [10, 20, 30, 31, 32, 33, 34, 35]
103 => [100, 101, 102, 103]
320 => [100, 200, 300, 310, 320]
354 => [100, 200, 300, 310, 320, 330, 340, 350, 351, 352, 353, 354]
1000 => [1000]
1001 => [1000, 1001]
3495 => [1000, 2000, 3000, 3100, 3200, 3300, 3400, 3410, 3420, 3430, 3440, 3450, 3460, 3470, 3480, 3490, 3491, 3492, 3493, 3494, 3495]
4037 => [1000, 2000, 3000, 4000, 4010, 4020, 4030, 4031, 4032, 4033, 4034, 4035, 4036, 4037]
84958320573493 => [10000000000000, 20000000000000, 30000000000000, 40000000000000, 50000000000000, 60000000000000, 70000000000000, 80000000000000, 81000000000000, 82000000000000, 83000000000000, 84000000000000, 84100000000000, 84200000000000, 84300000000000, 84400000000000, 84500000000000, 84600000000000, 84700000000000, 84800000000000, 84900000000000, 84910000000000, 84920000000000, 84930000000000, 84940000000000, 84950000000000, 84951000000000, 84952000000000, 84953000000000, 84954000000000, 84955000000000, 84956000000000, 84957000000000, 84958000000000, 84958100000000, 84958200000000, 84958300000000, 84958310000000, 84958320000000, 84958320100000, 84958320200000, 84958320300000, 84958320400000, 84958320500000, 84958320510000, 84958320520000, 84958320530000, 84958320540000, 84958320550000, 84958320560000, 84958320570000, 84958320571000, 84958320572000, 84958320573000, 84958320573100, 84958320573200, 84958320573300, 84958320573400, 84958320573410, 84958320573420, 84958320573430, 84958320573440, 84958320573450, 84958320573460, 84958320573470, 84958320573480, 84958320573490, 84958320573491, 84958320573492, 84958320573493]
47 -> ["01", "02", "03", "04", "14", "24", "34", "44", "54", "64", "74"]
? \$\endgroup\$