/**
 * @template T
 * @param {T[]} a
 * @param {T[]} b
 * @param {function(T,T):boolean} elements_equal
 * @param {*} [element_equal_context]
 * @returns {boolean}
 */
export function isArraysEqualWithComparator(a, b, elements_equal, element_equal_context) {
    if (a === b) {
        // same object
        return true;
    }

    if (a === null || b === null || a === undefined || b === undefined) {
        // check if one of the arrays is missing
        return false
    }

    const element_count = a.length;

    if (element_count !== b.length) {
        return false;
    }

    for (let i = 0; i < element_count; i++) {
        const aE = a[i];
        const bE = b[i];

        if (!elements_equal.call(element_equal_context, aE, bE)) {
            return false;
        }
    }

    return true;
}
