Topic describes

Their thinking

  • The end of the loop is 10** digits minus 1
  • Start at 1 and loop to the specified position.

The problem solving code

var printNumbers = function(n) {

    // Define where the loop ends
    const deadline = 10 ** n - 1;
    // Define the final array returned
    const res = [];
    // Start the loop
    for (let i = 1; i <= deadline; i++) {
        res.push(i)
    }
    return res;
}
Copy the code

revelation

  • Learn JS power operations.