Thursday, 25 May 2017

learnyounode: juggling async issue

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:

  1. 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. "
  2. 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. "

  3. 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. "

  4. 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. "

  5. 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. "

  6. 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. "

  7. ACTUAL: ""

  8. EXPECTED: ""


via Dushyant Joshi

No comments:

Post a Comment