en.javascript.info/1-js/8-more-functions/5-settimeout-setinterval/3-rewrite-settimeout-0/task.md
Ilya Kantor d4c714cbe1 work
2016-08-05 16:53:08 +03:00

30 lines
383 B
Markdown

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();
```