<commit_before>import Types = require('Adhocracy/Types');


// Array Remove - By <NAME> (MIT Licensed)
export function cutArray(a : any[], from : number, to ?: number) : any[] {
    var rest = a.slice((to || from) + 1 || a.length);
    a.length = from < 0 ? a.length + from : from;
    a.push.apply(a, rest);
    return a;
};

export function isInfixOf(needle : any, hay : any[]) : boolean {
    return hay.indexOf(needle) !== -1;
};

export function parentPath(url : string) : string {
    return url.substring(0, url.lastIndexOf("/"));
};


// Do a deep copy on any javascript object.  The resuling object does
// not share sub-structures as the original.  (I think instances of
// classes other than Object, Array are not treated properly either.)
export function deepcp(i) {
    if (typeof(i) == 'object') {
        var o : Object;
        if (i == null)                o = null;
        else if (i instanceof Array)  o = new Array();
        else                          o = new Object();

        for (var x in i) o[x] = deepcp(i[x]);
        return o;
    } else {
        return i;
    }
}


// Compare two objects, and return a boolen that states whether they
// are equal.  (This is likely to be an approximation, but it should
// work at least for json objects.)
export function deepeq(a : any, b : any) : boolean {
    if (typeof a != typeof b)
        return false;

    if (typeof(a) == 'object') {
        if (a == null) return (b == null);

        for (var x in a) {
            if (!(x in b)) return false;
            if (!deepeq(a[x], b[x])) return false;
        }

        for (var x in b) {
            if (!(x in a)) return false;
        }
    }

    return true;
}<commit_msg>fix: Util.deepeq<commit_after>import Types = require('Adhocracy/Types');


// Array Remove - By <NAME> (MIT Licensed)
export function cutArray(a : any[], from : number, to ?: number) : any[] {
    var rest = a.slice((to || from) + 1 || a.length);
    a.length = from < 0 ? a.length + from : from;
    a.push.apply(a, rest);
    return a;
};

export function isInfixOf(needle : any, hay : any[]) : boolean {
    return hay.indexOf(needle) !== -1;
};

export function parentPath(url : string) : string {
    return url.substring(0, url.lastIndexOf("/"));
};


// Do a deep copy on any javascript object.  The resuling object does
// not share sub-structures as the original.  (I think instances of
// classes other than Object, Array are not treated properly either.)
export function deepcp(i) {
    if (typeof(i) == 'object') {
        var o : Object;
        if (i == null)                o = null;
        else if (i instanceof Array)  o = new Array();
        else                          o = new Object();

        for (var x in i) o[x] = deepcp(i[x]);
        return o;
    } else {
        return i;
    }
}


// Compare two objects, and return a boolen that states whether they
// are equal.  (This is likely to be an approximation, but it should
// work at least for json objects.)
export function deepeq(a : any, b : any) : boolean {
    if (typeof a !== typeof b)
        return false;

    if (typeof(a) === 'object') {
        if (a === null) return (b === null);

        for (var x in a) {
            if (!(x in b)) return false;
            if (!deepeq(a[x], b[x])) return false;
        }

        for (var x in b) {
            if (!(x in a)) return false;
        }
    }

    return a === b;
}
{'fraction_non_alphanumeric': 0.13905152224824355, 'fraction_numerical': 0.00234192037470726, 'mean_word_length': 2.11485870556062, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5136645', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1049, 'n_words': 408}