add snippet primes
This commit is contained in:
@ -8,4 +8,4 @@ Explain briefly how the snippet works.
|
|||||||
const functionName = arguments =>
|
const functionName = arguments =>
|
||||||
{functionBody}
|
{functionBody}
|
||||||
// functionName(sampleInput) -> sampleOutput
|
// functionName(sampleInput) -> sampleOutput
|
||||||
```
|
```
|
||||||
15
snippets/primes.md
Normal file
15
snippets/primes.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
### primes
|
||||||
|
|
||||||
|
It generates primes till a given number ```m
|
||||||
|
|
||||||
|
Explain briefly how the snippet works.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const primes = num =>{
|
||||||
|
var arr = Array.from({length:num-1}).map((x,i)=> i+2);
|
||||||
|
var sqroot = Math.floor(Math.sqrt(num));
|
||||||
|
var numsTillSqroot = Array.from({length:numb-1}).map((x,i)=> i+2);
|
||||||
|
arra.forEach(x => arr = arr.filter(y => ((y%x)!==0)||(y== x)));
|
||||||
|
return arr;
|
||||||
|
}// primes(10) -> [2,3,5,7]
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user