Further changes for the Use cases on the live site.
[yaffs-website] / node_modules / phantomjs-prebuilt / lib / phantom / examples / sleepsort.js
1 // sleepsort.js - Sort integers from the commandline in a very ridiculous way: leveraging timeouts :P
2
3 "use strict";
4 var system = require('system');
5
6 function sleepSort(array, callback) {
7     var sortedCount = 0,
8         i, len;
9     for ( i = 0, len = array.length; i < len; ++i ) {
10         setTimeout((function(j){
11             return function() {
12                 console.log(array[j]);
13                 ++sortedCount;
14                 (len === sortedCount) && callback();
15             };
16         }(i)), array[i]);
17     }
18 }
19
20 if ( system.args.length < 2 ) {
21     console.log("Usage: phantomjs sleepsort.js PUT YOUR INTEGERS HERE SEPARATED BY SPACES");
22     phantom.exit(1);
23 } else {
24     sleepSort(system.args.slice(1), function() {
25         phantom.exit();
26     });
27 }