I am trying to solve the Juggling Async problem of learnyounode.
The following is what I have tried. But I am not getting desired output. I can find the solution by searching in google. But what I want is to learn node fundamentals. Can somebody direct me where I am going wrong?
var http = require('http');
var bl = require('bl');
var output = [];
var cnt = 0;
for (var i in process.argv) {
  if (i > 1 ) {
    http.get(process.argv[i],function(response){
      response.pipe(bl(function(err,data){
        output[cnt] = data.toString();
        cnt++;
        if (output.length === (process.argv.length - 2)) {
          printResult(output);
        }
      }));
    });
  }
}
function printResult(output){
  for (var i = 0; i < output.length; i++) {
    console.log(output[i]);
  }
}
The output I am getting:
- ACTUAL: "Gutful of brickie where shazza got us some ripper. Come a bunyip with watch out for the dinky-di. You little ripper rotten mate lets get some larrikin. "
EXPECTED: "Gutful of brickie where shazza got us some ripper. Come a bunyip with watch out for the dinky-di. You little ripper rotten mate lets get some larrikin. "
ACTUAL: "Watch out for the aerial pingpong when she'll be right aussie rules footy. He hasn't got a battler mate lets throw a battler. "
EXPECTED: "Built like a feral no worries stands out like a bonzer. Come a grundies my flat out like a boardies. As dry as a mokkies no worries shazza got us some rock up. "
ACTUAL: "Built like a feral no worries stands out like a bonzer. Come a grundies my flat out like a boardies. As dry as a mokkies no worries shazza got us some rock up. "
EXPECTED: "Watch out for the aerial pingpong when she'll be right aussie rules footy. He hasn't got a battler mate lets throw a battler. "
ACTUAL: ""
- EXPECTED: ""
 
    