Comment

Comment by ricardobeat

javascript version for you:

   var numbers  = process.argv.slice(2)
     , output   = []
     , negative = []

   for (var i=0, ln=numbers.length; i<ln; i++){
      var n = +numbers[i]
      setTimeout((function(n){ return function(){
         if (n<0) negative.unshift(n)
         else output.push(n)
         if (output.length + negative.length === numbers.length) {
            return console.log(negative.concat(output))
         }
      }})(n), Math.abs(n)/1000)
   }
Works with negative numbers.

    $ node sleepsort -2 1 0.1 4 -1 7 -3 9
    [ -3, -2, -1, 0.1, 1, 4, 7, 9 ]
parent ricardobeat 15 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton