Test name | Executions per second |
---|---|
reverse | 30.1 Ops/sec |
sort | 30.3 Ops/sec |
var array = Array.from({ length: 10000 }, () => Math.floor(Math.random() * 10000))
var array = Array.from({ length: 10000 }, () => Math.floor(Math.random() * 10000))
array.forEach(n => {
const repeat = Math.sqrt(n);
const result = [[], []];
for (let i = 1; i <= repeat; i++) {
if(n % i === 0) {
result.push(i);
if (i !== repeat) result.push(n / i);
}
}
result.sort().reverse()[0];
}
)
array.forEach(n => {
const repeat = Math.sqrt(n);
const result = [[], []];
for (let i = 1; i <= repeat; i++) {
if(n % i === 0) {
result.push(i);
if (i !== repeat) result.push(n / i);
}
}
result.sort()[result.length-1];
}
)