Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 15 题(2019-08-09):修改以下 print 函数,使之输出 0 到 99,或者 99 到 0 #10

Open
qappleh opened this issue Aug 9, 2019 · 2 comments
Labels

Comments

@qappleh
Copy link
Owner

qappleh commented Aug 9, 2019

要求:

1、只能修改 setTimeout 到 Math.floor(Math.random() * 1000 的代码

2、不能修改 Math.floor(Math.random() * 1000

3、不能使用全局变量

function print(n){
  setTimeout(() => {
    console.log(n);
  }, Math.floor(Math.random() * 1000));
}
for(var i = 0; i < 100; i++){
  print(i);
}  
@qappleh qappleh changed the title 第 15 题:修改以下 print 函数,使之输出 0 到 99,或者 99 到 0 第 15 题(2019-08-09):修改以下 print 函数,使之输出 0 到 99,或者 99 到 0 Aug 9, 2019
@qappleh
Copy link
Owner Author

qappleh commented Aug 12, 2019

function print(n){
  setTimeout((() => {
    console.log(n)
    return ()=>{}
  }).call(n,[]), Math.floor(Math.random() * 1000));
}
for(var i = 0; i < 100; i++){
  print(i);
}  

@qappleh qappleh added the js label Nov 27, 2019
@Akimixu-19897
Copy link

为什么这边的call直接就把代码执行了啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants