X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=node_modules%2Fphantomjs-prebuilt%2Flib%2Fphantom%2Fexamples%2Fsleepsort.js;fp=node_modules%2Fphantomjs-prebuilt%2Flib%2Fphantom%2Fexamples%2Fsleepsort.js;h=7959799567b78a28d2a49873d29cccde7d724584;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/node_modules/phantomjs-prebuilt/lib/phantom/examples/sleepsort.js b/node_modules/phantomjs-prebuilt/lib/phantom/examples/sleepsort.js new file mode 100644 index 000000000..795979956 --- /dev/null +++ b/node_modules/phantomjs-prebuilt/lib/phantom/examples/sleepsort.js @@ -0,0 +1,27 @@ +// sleepsort.js - Sort integers from the commandline in a very ridiculous way: leveraging timeouts :P + +"use strict"; +var system = require('system'); + +function sleepSort(array, callback) { + var sortedCount = 0, + i, len; + for ( i = 0, len = array.length; i < len; ++i ) { + setTimeout((function(j){ + return function() { + console.log(array[j]); + ++sortedCount; + (len === sortedCount) && callback(); + }; + }(i)), array[i]); + } +} + +if ( system.args.length < 2 ) { + console.log("Usage: phantomjs sleepsort.js PUT YOUR INTEGERS HERE SEPARATED BY SPACES"); + phantom.exit(1); +} else { + sleepSort(system.args.slice(1), function() { + phantom.exit(); + }); +}