Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,5 @@
|
|||
Array.prototype.timeoutSort = function (f) {
|
||||
this.forEach(function (n) {
|
||||
setTimeout(function () { f(n) }, 5 * n)
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
[1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0].timeoutSort(function(n) { document.write(n + '<br>'); })
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Array.prototype.sleepSort = function(callback) {
|
||||
const res = [];
|
||||
for (let n of this)
|
||||
setTimeout(() => {
|
||||
res.push(n);
|
||||
if (this.length === res.length)
|
||||
callback(res);
|
||||
}, n + 1);
|
||||
return res;
|
||||
};
|
||||
|
||||
[1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0].sleepSort(console.log);
|
||||
// [ 1, 0, 2, 3, 4, 5, 5, 6, 7, 8, 9 ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue