This commit is contained in:
Angelos Chalaris
2017-12-27 11:02:46 +02:00
parent 37bb271221
commit 3d79413392
45 changed files with 89 additions and 91 deletions

View File

@ -6,11 +6,11 @@ Generate an array from `2` to the given number. Use `Array.filter()` to filter o
```js
const primes = num => {
let arr = Array.from({length:num-1}).map((x,i)=> i+2),
sqroot = Math.floor(Math.sqrt(num)),
numsTillSqroot = Array.from({length:sqroot-1}).map((x,i)=> i+2);
numsTillSqroot.forEach(x => arr = arr.filter(y => ((y%x)!==0)||(y==x)));
return arr;
}
// primes(10) -> [2,3,5,7]
let arr = Array.from({length: num - 1}).map((x, i) => i + 2),
sqroot = Math.floor(Math.sqrt(num)),
numsTillSqroot = Array.from({length: sqroot - 1}).map((x, i) => i + 2);
numsTillSqroot.forEach(x => arr = arr.filter(y => ((y % x) !== 0) || (y == x)));
return arr;
};
// primes(10) -> [2,3,5,7]
```