练习题4:间隔特定的时间执行函数
Open
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 6
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
有若干和函数(fn1,fn2,....fnn),需要编写一个函数,进行间隔特定的时间执行特定的函数
比如 隔间 1 秒执行 fn1 ,之后间隔 2 秒执行 fn2
比如 隔间立即执行 fn1,之后间隔 4 秒执行 fn3
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
async function fn(arr){
for(let item of arr){
await sleep(item.time).then(()=>{item.fn()})
}
}
fn([
{
time:1000,
fn(){
console.log('1秒后执行fn1')
}
},
{
time:2000,
fn(){
console.log('2秒后执行fn2')
}
}
])
fn([
{
time:0,
fn(){
console.log('立即执行fn1')
}
},
{
time:4000,
fn(){
console.log('4秒后执行fn2')
}
}
])
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the exercise 4 entry or related example in the repository, since no file or test is named. Implement the function described in the issue so each supplied callback runs after its specified delay, then verify both the one-second/two-second and immediate/four-second examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100