Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / phantomjs / lib / phantom / examples / sleepsort.js
1 // sleepsort.js - Sort integers from the commandline in a very ridiculous way: leveraging timeouts :P
2 var system = require('system');
3
4 function sleepSort(array, callback) {
5     var sortedCount = 0,
6         i, len;
7     for ( i = 0, len = array.length; i < len; ++i ) {
8         setTimeout((function(j){
9             return function() {
10                 console.log(array[j]);
11                 ++sortedCount;
12                 (len === sortedCount) && callback();
13             };
14         }(i)), array[i]);
15     }
16 }
17
18 if ( system.args < 2 ) {
19     console.log("Usage: phantomjs sleepsort.js PUT YOUR INTEGERS HERE SEPARATED BY SPACES");
20     phantom.exit(1);
21 } else {
22     sleepSort(Array.prototype.slice.call(system.args, 1), function() {
23         phantom.exit();
24     });
25 }