<commit_before>var factorial1 = function(n){
    var fact = 1;

    setTimeout(function(){
        console.log("TIMEOUT 0");
    }, 0);

    for (var i = 1; i <= n; i++) {
        console.log("step" + i);
        fact = fact * i;
    }

    console.log("step" + n);

    return fact;
};

var factorial2 = function(n, callback){
    var fact = 1;

    setTimeout(function(){
        console.log("TIMEOUT 0");
    }, 0);

    for (var i = 1; i <= n; i++) {
        console.log("step" + i);
        fact = fact * i;
    }

    console.log("step" + n);

    callback(null, fact);
};

var factorial3 = function(n, callback) {
    setTimeout(function(){
        console.log("TIMEOUT 0");
    }, 0);

    setImmediate(function(){
        var fact = 1;

        setTimeout(function(){
            console.log("TIMEOUT 0");
        }, 0);

        for (var i = 1; i <= n; i++) {
            console.log("step" + i);
            fact = fact * i;
        }
    
        console.log("step" + n);
    
        callback(null, fact);
    });
};

var factorial4 = function(n, callback) {
    var facter = function(fact, index, callback) {
        setTimeout(function(){
            console.log("TIMEOUT 0");
        }, 0);

        console.log("step" + index);
        fact = fact * index;

        if (index === n) {
            callback(null, fact);
            return;
        }

        setImmediate(function() {
            facter(fact, ++index, callback);
        });
    };

    setTimeout(function(){
        console.log("TIMEOUT 0");
    }, 0);

    facter(1, 1, callback);
};

var factorial5 = function(n, callback) {
    var facter = function(fact, index, callback) {
        console.log("step" + index);
        fact = fact * index;

        if (index === n) {
            callback(null, fact);
            return;
        }

        setTimeout(function(){
            console.log("TIMEOUT 0");
        }, 0);

        process.nextTick(function() {
            facter(fact, ++index, callback);
        });
    };

    setTimeout(function(){
        console.log("TIMEOUT 0");
    }, 0);

    facter(1, 1, callback);
};

var factorials = {
    "1":factorial1,
    "2":factorial2,
    "3":factorial3,
    "4":factorial4,
    "5":factorial5
};

// include the http module
var net = require("net");

// Create a TCP Server Instance and set an event listener & handler for the TCP connection event emitted by the server
var tcpServer = net.createServer(function(conn) {

    // Connection Information for Prefix Logging
    var connLogPrefix = "[" + conn.remoteAddress + ":" + conn.remotePort + "]";

    console.log(connLogPrefix, " Connected.");

    // Set an event listener & handler for the TCP data event emitted by the connection<commit_msg>Fix bug of endless loop if isNaN<commit_after>function isValid(n) {
    return !isNaN(n) && 0 < parseInt(n, 10);
}

var factorial1 = function(n) {
    var fact = 0;

    if (isValid(n)) {
        fact = 1;
        setTimeout(function(){
            console.log("TIMEOUT 0");
        }, 0);

        for (var i = 1; i <= n; i++) {
            console.log("step" + i);
            fact = fact * i;
        }

        console.log("step" + n);
    }

    return fact;
};

var factorial2 = function(n, callback){
    var fact = 0;

    if (isValid(n)) {
        fact = 1;

        setTimeout(function(){
            console.log("TIMEOUT 0");
        }, 0);

        for (var i = 1; i <= n; i++) {
            console.log("step" + i);
            fact = fact * i;
        }

        console.log("step" + n);
    }

    callback(null, fact);
};

var factorial3 = function(n, callback) {

        setTimeout(function () {
            console.log("TIMEOUT 0");
        }, 0);

        setImmediate(function () {
            var fact = 0;
            if (isValid(n)) {
                fact = 1;

                setTimeout(function () {
                    console.log("TIMEOUT 0");
                }, 0);

                for (var i = 1; i <= n; i++) {
                    console.log("step" + i);
                    fact = fact * i;
                }

                console.log("step" + n);
            }

            callback(null, fact);
        });
};

var factorial4 = function(n, callback) {
    var facter = function(fact, index, callback) {
        setTimeout(function(){
            console.log("TIMEOUT 0");
        }, 0);

        if (isValid(n)) {
            console.log("step" + index);
            fact = fact * index;

            if (index === n) {
                callback(null, fact);
                return;
            }

            setImmediate(function() {
                facter(fact, ++index, callback);
            });
        }
        else {
            callback(null, 0);
            return;
        }
    };

    setTimeout(function(){
        console.log("TIMEOUT 0");
    }, 0);

    facter(1, 1, callback);
};

var factorial5 = function(n, callback) {
    var facter = function(fact, index, callback) {
        if (isValid(n)) {
            console.log("step" + index);
            fact = fact * index;

            if (index === n) {
                callback(null, fact);
                return;
            }

            setTimeout(function () {
                console.log("TIMEOUT 0");
            }, 0);

            process.nextTick(function () {
                facter(fact, ++index, callback);
            });
        }
        else {
            callback(null, fact);
            return;
        }
    };

    setTimeout(function(){
        console.log("TIMEOUT 0");
    }, 0);

    facter(1, 1, callback);
};

var factorials = {
    "1":factorial1,
    "2":factorial2,
    "3":factorial3,
    "4":factorial4,
    "5":factorial5
};

// include the http module
var net = require("net");

// Create a TCP Server Instance and set an event listener & handler for the TCP connection event emitted by the server
var tcpServer = net.createServer(function(conn) {

    // Connection Information for Prefix Logging
    var connLogPrefix = "[" + conn.remoteAddress + ":" + conn.remotePort + "]";

    console.log(connLogPrefix, " Connected.");

    // Set an event listener & handler for the TCP data event emitted by the connection
{'fraction_non_alphanumeric': 0.14714424007744434, 'fraction_numerical': 0.014359470797031301, 'mean_word_length': 1.6696813092161928, 'pattern_counts': {'":': 12, '<': 10, '<?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': '6832852', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1821, 'n_words': 470}