mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-04 07:46:43 +02:00
Further reduce prime complexity
This commit is contained in:
@@ -26,7 +26,8 @@ module.exports = class PrimeCommand extends Command {
|
||||
|
||||
isPrime(number) {
|
||||
if (number < 2) return false;
|
||||
for (let i = 2, s = Math.sqrt(number); i <= s; i++) {
|
||||
const sqrt = Math.sqrt(number);
|
||||
for (let i = 2; i <= sqrt; i++) {
|
||||
if (number % i === 0) return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user