This commit is contained in:
Ilya Kantor 2016-08-05 16:53:08 +03:00
parent 4c531b5ae7
commit d4c714cbe1
261 changed files with 7370 additions and 546 deletions

View file

@ -0,0 +1,23 @@
```js run
let i = 0;
let start = Date.now();
let timer = setInterval(count, 0);
function count() {
for(let j = 0; j < 1000000; j++) {
i++;
}
if (i == 1000000000) {
alert("Done in " + (Date.now() - start) + 'ms');
cancelInterval(timer);
}
}
```

View file

@ -0,0 +1,30 @@
importance: 4
---
# Rewrite setTimeout with setInterval
Rewrite the split counting function from setTimeout to setInterval:
```js run
let i = 0;
let start = Date.now();
function count() {
if (i == 1000000000) {
alert("Done in " + (Date.now() - start) + 'ms');
} else {
setTimeout(count, 0);
}
for(let j = 0; j < 1000000; j++) {
i++;
}
}
count();
```