Sha256: e8d7bfc2677eff54e405003f2dcc5d598dd77ae7ecd0020b0cf33ae8b42cdc45

Contents?: true

Size: 758 Bytes

Versions: 17

Compression:

Stored size: 758 Bytes

Contents

// sleepsort.js - Sort integers from the commandline in a very ridiculous way: leveraging timeouts :P
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 < 2 ) {
    console.log("Usage: phantomjs sleepsort.js PUT YOUR INTEGERS HERE SEPARATED BY SPACES");
    phantom.exit(1);
} else {
    sleepSort(Array.prototype.slice.call(system.args, 1), function() {
        phantom.exit();
    });
}

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
hooch-0.4.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
hooch-0.4.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
hooch-0.3.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
hooch-0.2.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
hooch-0.2.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
hooch-0.1.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
hooch-0.0.8 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
hooch-0.0.7 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
hooch-0.0.6 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
entangled-0.0.16 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
entangled-0.0.15 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
entangled-0.0.14 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
entangled-0.0.13 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
entangled-0.0.12 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
entangled-0.0.11 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/sleepsort.js
entangled-0.0.10 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/sleepsort.js