Logarithmic growth counter I'm looking for a way to have an logarithmic incremental counter. The counter goal is related to a numeric value than goes from 1 to Infinity. The counter maximum value should be 1000. 
The sequence looks like this:


number is below 10, increment by 1:

1,2,3...7,8,9,10
number is above 10, increment by ^10 when the number reaches the counter

100, 1000 stop at 1000


This is what I wrote so far (javascript):



let i = 0
let mod = 10
let result = document.getElementById('result')
result.innerText = ''

while (++i &lt; 7322) {
  mod *= mod &lt; 1000 &amp;&amp; i === mod * 10 ? 10 : 1

  if (i &lt; 10 || i % mod === 0) {
    //the further the `i` value is, the less this will be called
    result.innerText += i + ' pass the test. Mod is ' + mod + '.\n'
  }
}
&lt;span id="result"&gt;&lt;/span&gt;




I'm sure there is a more elegant way of doing this but can't get my hand on it. Do you have ideas on how to simplify the algorithm?
Your solution is a bit wasteful by generating and testing all integers in the desired range while you actually only need a handful of them. 

A big improvement in terms of performance is to avoid modulo arithmetic and increase the step-size tenfold whenever you finished iterating a sub-range 1-9, 10-99, 100-999 and so on:



let max = 7322;
let step = 1;
let next = 10;

while (step &lt; 1000 &amp;&amp; next &lt; max) {
  for (let i = step; i &lt; next; i += step) {
    console.log(i);
  }
  step = next;
  next *= 10;
}

for (let i = step; i &lt; max; i += step) {
  console.log(i);
}




Of course, you might want to encapsulate above code in a function or even more versatile, a generator function and replace console.log(i); with yield i;.

However, since you only have four different step-sizes of 1, 10, 100, and 1000 you can encode them manually and come up with an even simpler generator function as follows:



// Generate logarithmic range from 1 to max (excluded):
function* logRange(max) {
  for (let i = 1; i &lt; max &amp;&amp; i &lt; 10; i += 1) yield i;
  for (let i = 10; i &lt; max &amp;&amp; i &lt; 100; i += 10) yield i;
  for (let i = 100; i &lt; max &amp;&amp; i &lt; 1000; i += 100) yield i;
  for (let i = 1000; i &lt; max; i += 1000) yield i;
}

// Example:
for (let i of logRange(7322)) console.log(i);




This avoids modulo arithmetic, computes only the desired numbers and is pretty easy to understand.