Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
How to generate numbers as multiples of 10s in particular manner?

How to generate numbers in the following pattern in js?

const output = [1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800,900,1000,2000,3000,4000,5000, ... ]
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Here is another solution. Basically you loop through the numbers 1-9 again and again, multiplying by 1, 10, 100 etc.

const maxExponent = 5;
let exponent = 0;
let result = [];

while (exponent <= maxExponent) {
    for (let i = 1; i < 10; i++) {
        result.push(i * Math.pow(10, exponent));
    }
    exponent++;
}
console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

You could take the logarithm of 10 and add one to the found digit.

const
    fn = i => {
        const l = Math.floor(Math.log10(i)),
              d = i / 10 ** l;
        return (d + 1) * 10 ** l;
        
    };

for (i = 1; i < 10000; i = fn(i)) {
    console.log(i);
}
.as-console-wrapper { max-height: 100% !important; top: 0; }

A non math approach

const
    fn = i => +i.toString().replace(/./, d => +d + 1);

for (i = 1; i < 10000; i = fn(i)) {
    console.log(i);
}
.as-console-wrapper { max-height: 100% !important; top: 0; }

about 4 years ago · Juan Pablo Isaza Report

0

Not actually Math but working using string.repeat :)

    max_zeros = 5;
    cur_zeros = 0;
    zero_string = '0';
    output = [];

    for (var cur_zeros = 0; cur_zeros <= max_zeros; cur_zeros++) {
    
        for (var i = 1; i < 10; i++) {
            output.push( parseInt(i + zero_string.repeat(cur_zeros)) )
        }   
    
    }
    console.log(output)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!