1 // sleepsort.js - Sort integers from the commandline in a very ridiculous way: leveraging timeouts :P
2 var system = require('system');
4 function sleepSort(array, callback) {
7 for ( i = 0, len = array.length; i < len; ++i ) {
8 setTimeout((function(j){
10 console.log(array[j]);
12 (len === sortedCount) && callback();
18 if ( system.args < 2 ) {
19 console.log("Usage: phantomjs sleepsort.js PUT YOUR INTEGERS HERE SEPARATED BY SPACES");
22 sleepSort(Array.prototype.slice.call(system.args, 1), function() {