import { assert } from "../assert.js";

/**
 * Compute the largest positive integer divisor of a given "product" value
 * @param {number} product
 * @param {number} limit
 * @returns {number}
 */
export function computeWholeDivisorLow(product, limit) {

    assert.isNumber(product, 'product');
    assert.isInteger(product, 'product');

    assert.isNumber(limit, 'limit');
    assert.isInteger(limit, 'limit');

    assert.isFinite(limit,'limit');
    assert.isFinite(product,'product');

    let i = limit;

    while (i > 1) {

        if (product % i === 0) {
            break;
        }

        i--;

    }

    return i;
}
