chenhuiYj / chenhuiYj/note

练习题2:不使用数组内置 API 实现等差数组

Open
#13 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
6
Forks
0
PR merge metrics
No merged PRs in 30d

Description

不使用 for, while 以及 所有数组内置的 API ,实现将一个空数组赋值成 [0,2,4,6,8....100]

实现方式

function handle(){
    let arr=[]
    let item=0
    function fn(){
        arr[item]=item*2
        item+=1
        if(item<=50){
            fn()
        }
    }
    fn()
    return arr
}
handle()

把代码贴到 console 就可以正常的输出了,但是如果下次如果要求输出 [0,2,4....200]呢?这个很好解决,只要加个参数 num 就可以实现。规定循环多少次才输出

function handle(num){
    let arr=[]
    let item=0
    function fn(){
        arr[item]=item*2
        item+=1
        if(item<=num){
            fn()
        }
    }
    fn()
    return arr
}
handle(50)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the JavaScript exercise and examples in the issue body, then run the shown behavior in a browser console or JavaScript runtime. Confirm that the result contains the requested even-number sequence and that the parameterized case changes the endpoint as described; the issue does not name a repository file to update.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
content, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.