<commit_before>// Custom `Array.find` implementation for legacy browsers.
export function find<T>(arr: T[], predicate: (value: T, index: number, arr: T[]) => boolean): T | undefined {
    for (let i = 0, ln = arr.length; i < ln; i++) {
        const value = arr[i];
        if (predicate(value, i, arr)) {
            return value;
        }
    }
}

/**
 * Returns the minimum and maximum value in the given iterable using natural order.
 * If the iterable contains no comparable values, returns `undefined`.
 * @param values
 */
export function extent<T>(values: T[]): [T, T] | undefined {
    const n = values.length;
    let i = -1;
    let value;
    let min;
    let max;

    while (++i < n) { // Find the first comparable finite value.
        if ((value = values[i]) != null && value >= value) {
            min = max = value;
            while (++i < n) { // Compare the remaining values.
                if ((value = values[i]) != null) {
                    if (min > value) {
                        min = value;
                    }
                    if (max < value) {
                        max = value;
                    }
                }
            }
        }
    }

    return typeof min === 'undefined' || typeof max === 'undefined' ? undefined : [min, max];
}

export function finiteExtent<T>(values: T[]): [T, T] | undefined {
    const n = values.length;
    let i = -1;
    let value;
    let min;
    let max;

    while (++i < n) { // Find the first comparable finite value.
        if ((value = values[i]) != null && value >= value && isFinite(value as any)) {
            min = max = value;
            while (++i < n) { // Compare the remaining values.
                if ((value = values[i]) != null && isFinite(value as any)) {
                    if (min > value) {
                        min = value;
                    }
                    if (max < value) {
                        max = value;
                    }
                }
            }
        }
    }

    return min === undefined || max === undefined ? undefined : [min, max];
}

/**
 * This method will only return `undefined` if there's not a single valid finite number present
 * in the given array of values. Date values will be converted to timestamps.
 * @param values
 */
export function numericExtent<T>(values: T[]): [number, number] | undefined {
    const calculatedExtent = finiteExtent(values);

    if (typeof calculatedExtent === 'undefined') {
        return;
    }

    const [a, b] = calculatedExtent;
    const min = a instanceof Date ? a.getTime() : a;
    const max = b instanceof Date ? b.getTime() : b;

    if (typeof min === 'number' && isFinite(min) && typeof max === 'number' && isFinite(max)) {
        return [min, max];
    }
}

/**
 * finds the min and max using a process appropriate for stacked values. Ie,
 * summing up the positive and negative numbers, and returning the totals of each
 */
export function findMinMax(values: number[]): { min: number, max: number } {
    let min = 0;
    let max = 0;

    for (const value of values) {
        if (value < 0) {
            min += value;
        } else {
            max += value;
        }
    }

    return {min, max};
}

export function findLargestMinMax(totals: { min: number, max: number }[]): { min: number, max: number } {
    let min = 0;
    let max = 0;

    for (const total of totals) {
        if (total.min < min) {
            min = total.min;
        }
        if (total.max > max) {
            max = total.max;
        }
    }

    return {min, max};
}

export function copy(array: any[], start: number = 0, count: number = array.length): any[] {
    const result = [];
    let n = array.length;

    if (n) {
        for (let i = 0; i < count; i++) {
            result.push(array[(start + i) % n]);
        }
    }

    return result;
}
<commit_msg>array.findIndex method.<commit_after>// Custom `Array.find` implementation for legacy browsers.
export function find<T>(arr: T[], predicate: (item: T, index: number, arr: T[]) => boolean): T | undefined {
    for (let i = 0; i < arr.length; i++) {
        const value = arr[i];
        if (predicate(value, i, arr)) {
            return value;
        }
    }
}

export function findIndex<T>(arr: T[], predicate: (item: T, index: number, arr: T[]) => boolean): number {
    for (let i = 0; i < arr.length; i++) {
        if (predicate(arr[i], i, arr)) {
            return i;
        }
    }
    return -1;
}

/**
 * Returns the minimum and maximum value in the given iterable using natural order.
 * If the iterable contains no comparable values, returns `undefined`.
 * @param values
 */
export function extent<T>(values: T[]): [T, T] | undefined {
    const n = values.length;
    let i = -1;
    let value;
    let min;
    let max;

    while (++i < n) { // Find the first comparable finite value.
        if ((value = values[i]) != null && value >= value) {
            min = max = value;
            while (++i < n) { // Compare the remaining values.
                if ((value = values[i]) != null) {
                    if (min > value) {
                        min = value;
                    }
                    if (max < value) {
                        max = value;
                    }
                }
            }
        }
    }

    return typeof min === 'undefined' || typeof max === 'undefined' ? undefined : [min, max];
}

export function finiteExtent<T>(values: T[]): [T, T] | undefined {
    const n = values.length;
    let i = -1;
    let value;
    let min;
    let max;

    while (++i < n) { // Find the first comparable finite value.
        if ((value = values[i]) != null && value >= value && isFinite(value as any)) {
            min = max = value;
            while (++i < n) { // Compare the remaining values.
                if ((value = values[i]) != null && isFinite(value as any)) {
                    if (min > value) {
                        min = value;
                    }
                    if (max < value) {
                        max = value;
                    }
                }
            }
        }
    }

    return min === undefined || max === undefined ? undefined : [min, max];
}

/**
 * This method will only return `undefined` if there's not a single valid finite number present
 * in the given array of values. Date values will be converted to timestamps.
 * @param values
 */
export function numericExtent<T>(values: T[]): [number, number] | undefined {
    const calculatedExtent = finiteExtent(values);

    if (typeof calculatedExtent === 'undefined') {
        return;
    }

    const [a, b] = calculatedExtent;
    const min = a instanceof Date ? a.getTime() : a;
    const max = b instanceof Date ? b.getTime() : b;

    if (typeof min === 'number' && isFinite(min) && typeof max === 'number' && isFinite(max)) {
        return [min, max];
    }
}

/**
 * finds the min and max using a process appropriate for stacked values. Ie,
 * summing up the positive and negative numbers, and returning the totals of each
 */
export function findMinMax(values: number[]): { min: number, max: number } {
    let min = 0;
    let max = 0;

    for (const value of values) {
        if (value < 0) {
            min += value;
        } else {
            max += value;
        }
    }

    return {min, max};
}

export function findLargestMinMax(totals: { min: number, max: number }[]): { min: number, max: number } {
    let min = 0;
    let max = 0;

    for (const total of totals) {
        if (total.min < min) {
            min = total.min;
        }
        if (total.max > max) {
            max = total.max;
        }
    }

    return {min, max};
}

export function copy(array: any[], start: number = 0, count: number = array.length): any[] {
    const result = [];
    let n = array.length;

    if (n) {
        for (let i = 0; i < count; i++) {
            result.push(array[(start + i) % n]);
        }
    }

    return result;
}

{'fraction_non_alphanumeric': 0.13594787620598922, 'fraction_numerical': 0.002756546798646786, 'mean_word_length': 1.7420130539333563, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 25, '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': '3627552', 'n_tokens_mistral': 2383, 'n_tokens_neox': 2293, 'n_words': 825}