const createNum=(maxNum)=>{
constary_result=[];
for (let index=1; index<maxNum;index++){
aary_result.push(index);
if(index===maxNum){
returnary_result;
}
}
};
console.log(createNum(100));
// result
// [1, 2, 3, ..., 100]
Specifies a number and inserts it into the function.
Then an array is created, and 1, 2, 3, and 4 are sequentially incorporated into the array.
I thought the number would be substituted and then stopped, and the array would be returned.
Thank you for your cooperation.
javascript array
for (let index=1; index<maxNum;index++)
Because index
is less than maxNum
, the following logic is not performed:
if(index===maxNum){
returnary_result;
}
Change the for statement to the following and
for (let index=1; index<maxNum;index++)
You can revert at the end of the loop (returnary_result;
).
const createNum=(maxNum)=>{
constary_result=[];
for (let index=1; index<=maxNum;index++) {
aary_result.push(index);
}
returnary_result;
};
console.log(createNum(100));
© 2025 OneMinuteCode. All rights reserved.