src/modules/misc/utils.js
// finds all factors of an Integer returns them in complementary pairs
finds all factors of an Integer returns them in complementary pairs
finds all factors of an Integer returns them in complementary pairs
function findFactors(n) {
    if (isPrime(n)) return [
        [1, n]
    ];
    const isEven = n % 2 === 0;
    const inc = isEven ? 1 : 2;
    const factors = [
        [1, n]
    ];
    const root = Math.floor(Math.sqrt(n));
    for (let curFactor = isEven ? 2 : 3; curFactor <= root; curFactor += inc) {
        if (n % curFactor !== 0) continue;
        let compliment = n / curFactor;
        factors.push([curFactor, compliment]);
    }
    return factors;
}
function findFactors ( n ) { if ( isPrime ( n ) ) return [ [ 1 , n ] ] ; const isEven = n % 2 === 0 ; const inc = isEven ? 1 : 2 ; const factors = [ [ 1 , n ] ] ; const root = Math . floor ( Math . sqrt ( n ) ) ; for ( let curFactor = isEven ? 2 : 3 ; curFactor <= root ; curFactor += inc ) { if ( n % curFactor !== 0 ) continue ; let compliment = n / curFactor ; factors . push ( [ curFactor , compliment ] ) ; } return factors ; }
finds all factors of an Integer returns them in complementary pairs
finds all factors of an Integer returns them in complementary pairs