Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

Comment by nlco

15 years ago

your code can be simplified a bit:

    function sleep_sort (inputs) {
      function child (number) {
        setTimeout(function () {console.log(number)}, Math.pow(2,number))
      }

      for (var i = 0; i < inputs.length; ++i)
        child(inputs[i])
    }

    sleep_sort(process.argv.slice(2));

1 comment

nlco

Reply

ricardobeat  15 years ago

That won't work for numbers < -5 and has a much longer worst case.

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities