phantomjs/examples/sleepsort.coffee

21 lines
499 B
CoffeeScript
Raw Normal View History

2011-06-17 00:56:06 +04:00
###
Sort integers from the command line in a very ridiculous way: leveraging timeouts :P
###
system = require 'system'
if system.args.length < 2
console.log "Usage: phantomjs sleepsort.coffee PUT YOUR INTEGERS HERE SEPARATED BY SPACES"
phantom.exit 1
2011-06-17 00:56:06 +04:00
else
sortedCount = 0
args = Array.prototype.slice.call(system.args, 1)
for int in args
setTimeout (do (int) ->
2011-06-17 00:56:06 +04:00
->
console.log int
2011-06-17 00:56:06 +04:00
++sortedCount
phantom.exit() if sortedCount is args.length),
2011-06-17 00:56:06 +04:00
int