<commit_before>"use strict";

var http = require('http');
var async = require('async');
var bl = require('bl');

var urls = [];
for (var i = 2; i <= 4; i++) {
	urls.push(process.argv[i]);
};

async.parallel([
    function(callback){
        http.get(urls[0], function (response) {
			response.setEncoding('utf8');
			// response.on('data', function (chunk) {
			response.pipe(bl(function (err, data) {
				if (err) {
					return callback(err);
				}

				callback(null, data.toString());
			}));
		});
    },
    function(callback){
        http.get(urls[1], function (response) {
			response.setEncoding('utf8');
			// response.on('data', function (chunk) {
			response.pipe(bl(function (err, data) {
				if (err) {
					return callback(err);
				}

				callback(null, data.toString());
			}));
		});
    },
    function(callback){
        http.get(urls[2], function (response) {
			response.setEncoding('utf8');
			// response.on('data', function (chunk) {
			response.pipe(bl(function (err, data) {
				if (err) {
					return callback(err);
				}

				callback(null, data.toString());
			}));
		});
    }
],
// optional callback
function(err, results){
    // the results array will equal ['one','two'] even though
    // the second function had a shorter timeout.
    for (var i = 0; i < results.length; i++) {
    	console.log(results[i]);
    };
});

/* Official answer:

*/<commit_msg>Added official answer for 09 and made it more DRY - could be better<commit_after>"use strict";

var http = require('http');
var async = require('async');
var bl = require('bl');

var urls = [];
for (var i = 2; i <= 4; i++) {
	urls.push(process.argv[i]);
};

var getHttp = function getHttp (index, callback) {
	http.get(urls[0 + index], function (response) {
		response.setEncoding('utf8');
		// response.on('data', function (chunk) {
		response.pipe(bl(function (err, data) {
			if (err) {
				return callback(err);
			}

			callback(null, data.toString());
		}));
	});
}

async.parallel([
    function(callback){
        getHttp(0, callback);
    },
    function(callback){
        getHttp(1, callback);
    },
    function(callback){
        getHttp(2, callback);
    }
],
// optional callback
function(err, results){
    // the results array will equal ['one','two'] even though
    // the second function had a shorter timeout.
    for (var i = 0; i < results.length; i++) {
    	console.log(results[i]);
    };
});

/* Official answer:
var http = require('http')
var bl = require('bl')
var results = []
var count = 0

function printResults () {
	for (var i = 0; i < 3; i++)
		console.log(results[i])
}

function httpGet (index) {
	http.get(process.argv[2 + index], function (response) {
		response.pipe(bl(function (err, data) {
			if (err)
				return console.error(data)

			results[index] = data.toString()
			count++

			if (count == 3) // yay! we are the last one!
				printResults()
		}))
	})
}

for (var i = 0; i < 3; i++)
	httpGet(i)
*/
{'fraction_non_alphanumeric': 0.18299319727891156, 'fraction_numerical': 0.008843537414965987, 'mean_word_length': 3.045392022008253, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '343839', 'n_tokens_mistral': 1088, 'n_tokens_neox': 977, 'n_words': 253}