<commit_before>function count_chars (str, mode) {
    // http://kevin.vanzonneveld.net
    // +   original by: <NAME> (http://magnetiq.com)
    // +    tweaked by: Jack
    // +   bugfixed by: <NAME>
    // +      input by: <NAME> (http://brett-zamir.me)
    // +   bugfixed by: <NAME> (http://kevin.vanzonneveld.net)
    // *     example 1: count_chars("Hello World!", 1);
    // *     returns 1: "Hd e!lWor"

    var histogram = {}, tmp_arr = [];
    var key, i, code, strl = 0;
    var argc = arguments.length;
    var mode_even = 0;

    if (argc == 1) {
        mode = 0;
    }

    mode_even = (mode & 1) == 0;
    if (mode_even) {
        for (i = 1; i < 256; ++i) {
            histogram[i] = 0;
        }
    }

    str += '';

    strl = str.length;
    for (i = 0; i < strl; ++i) {
        code = str.charCodeAt(i);
        if (code in histogram) {
            ++histogram[code];
        } else {
            histogram[code] = 1;
        }
    }

    if (mode > 0) {
        for (key in histogram) {
            if (histogram[key] == 0 != mode_even) {
                delete histogram[key];
            }
        }
    }

    if (mode < 3) {
        return histogram;
    } else {
        for (key in histogram) {
            tmp_arr.push(String.fromCharCode(key));
        }
        return tmp_arr.join("");
    }
}<commit_msg>PHP returns the result arranged by ASCII codes (!HWdelor); previous version returns first come, first served (Helo Wrd!).<commit_after>function count_chars (str, mode) {
    // http://kevin.vanzonneveld.net
    // +   original by: <NAME> (http://magnetiq.com)
    // +    tweaked by: Jack
    // +   bugfixed by: <NAME>
    // +      input by: <NAME> (http://brett-zamir.me)
    // +   bugfixed by: <NAME> (http://kevin.vanzonneveld.net)
    // +    revised by: Theriault
    // *     example 1: count_chars("Hello World!", 3);
    // *     returns 1: "!HWdelor"
    // *     example 2: count_chars("Hello World!", 1);
    // *     returns 2: {32:1,33:1,72:1,87:1,100:1,101:1,108:3,111:2,114:1}
    var result = {}, resultArr = [], i;

    str = ('' + str).split('').sort().join('').match(/(.)\1*/g);

    if ((mode & 1) == 0) {
        for (i = 0; i != 256; i++) {
             result[i] = 0;
        }
    }

    if (mode === 2 || mode === 4) {

        for (i = 0; i != str.length; i += 1) {
             delete result[str[i].charCodeAt(0)];
        }
        for (i in result) {
            result[i] = (mode === 4) ? String.fromCharCode(i) : 0;
        }

    } else if (mode === 3) {

        for (i = 0; i != str.length; i += 1) {
             result[i] = str[i].slice(0, 1);
        }

    } else {

        for (i = 0; i != str.length; i += 1) {
             result[str[i].charCodeAt(0)] = str[i].length;
        }

    }
    if (mode < 3) {
        return result;
    }

    for (i in result) {
       resultArr.push(result[i]);
    }
    return resultArr.join('');    
}
{'fraction_non_alphanumeric': 0.1832191780821918, 'fraction_numerical': 0.02773972602739726, 'mean_word_length': 1.6315315315315315, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 12, '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': '4989284', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1047, 'n_words': 247}