at least use sqrt for no waste of execution time
exemple : 1000000
=> 1x100000
=> 2x 50000
=> until 1000x1000;
rather make 1000000 loops, you have 1000; not a great deal but much much save compute memory.
my suggestion
export function properDivisors(x: number): number[] {
const num = Math.abs(x);
const a:number[] = [];
const LIMIT = Math.sqrt(num)
for (let i=1; i<LIMIT; i++){
if (num % i===0){
a.push(i);
a.push(num/i) // if have rest of 0, the division is not a float number
}
return uniq(a);
}
https://en.wikipedia.org/wiki/Prime_number
relative to testing prime number because for testing prime number, we have to find if there are no devider except 1 and himself .
I'm sure for big number there are few tricks to make it faster : /
PostScriptum: I see that many function on fetch factor of, not have so clever algo and put a tons of loops for litterally nothing.
at least use sqrt for no waste of execution time exemple : 1000000 => 1x100000 => 2x 50000 => until 1000x1000;
rather make 1000000 loops, you have 1000; not a great deal but much much save compute memory.
my suggestion
https://en.wikipedia.org/wiki/Prime_number relative to testing prime number because for testing prime number, we have to find if there are no devider except 1 and himself .
I'm sure for big number there are few tricks to make it faster : /
PostScriptum: I see that many function on fetch factor of, not have so clever algo and put a tons of loops for litterally nothing.