Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/fixtures/gen-twice-issue-3597/new.js
13399 views
1
/**
2
* Finds all prime numbers up to a given limit `n`.
3
* @param {number} n - The limit to find primes up to.
4
* @returns {number[]} An array of prime numbers up to `n`.
5
*/
6
function findPrimes(n) {
7
let primes = [];
8
// Loop through all numbers from 2 to `n`
9
for (let i = 2; i < n; i++) {
10
let isPrime = true;
11
// Check if `i` is divisible by any number from 2 to the square root of `i`
12
for (let j = 2; j <= Math.sqrt(i); j++) {
13
if (i % j === 0) {
14
isPrime = false;
15
break;
16
}
17
}
18
// If `i` is not divisible by any number, it is a prime number
19
if (isPrime) {
20
primes.push(i);
21
}
22
}
23
return primes;
24
}
25
26
console.log(findPrimes(100));
27
28
29