o9s
is a microblog
home archives search feed blogroll


sleepsort

A joke algorithm to sort numbers.

const sleepsort = (array) => array.forEach(
    (item) => setTimeout(() => console.log(item), item * 1000)
);

sleepsort([5, 3, 2, 7]);

// Output:
2 // ~2s later
3 // ~1s later
5 // ~2s later
7 // ~2s later

=>

<o9> i overdid arrow functions
<develope1> the more the better programmer you are
Posted on 2018-01-12   #javascript     #irc  






← Next post    ยท    Previous post →