blob: 11ed1d62db332e72cd3d9def70aa6019c5221c56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/usr/bin/env node
"use strict";
// let us make an unsorted array
let array = Array(10)
.fill()
.map((n, i) => 1 + i)
.map((value) => ({ value, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value);
console.log(array.join(" "));
// here, we're helped by the fact that JS does things at the
// millisecond level, not the second level
for (let i of array) {
setTimeout(() => {
process.stdout.write(i + " ");
}, i);
}
|