un peu plus d'aide pour Eratosthene
This commit is contained in:
23
R4.01_R4.A.10/td_tp/tp1/src/eratosthene/eratosthene.js
Normal file
23
R4.01_R4.A.10/td_tp/tp1/src/eratosthene/eratosthene.js
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
function eratosthene(n)
|
||||
{
|
||||
let primes = [];
|
||||
let filterArray = [];
|
||||
for(let i = 2; i <=n; i++){
|
||||
// TODO
|
||||
}
|
||||
return primes;
|
||||
}
|
||||
|
||||
function eratosthene1(n)
|
||||
{
|
||||
let numbers = Array.from({length : n - 2}, (v,k) => k + 2);
|
||||
let p ,primes = [];
|
||||
|
||||
while(numbers.length){
|
||||
[p,...numbers] = numbers;
|
||||
numbers = numbers.filter( x => x%p != 0);
|
||||
primes = [...primes,p];
|
||||
}
|
||||
return primes;
|
||||
}
|
||||
Reference in New Issue
Block a user