From 662d643069900b375c33ce2b6b454e95df8ac129 Mon Sep 17 00:00:00 2001 From: Rohit Date: Thu, 21 Dec 2017 15:50:22 +0530 Subject: [PATCH] add snippet primes --- snippet-template.md | 2 +- snippets/primes.md | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 snippets/primes.md diff --git a/snippet-template.md b/snippet-template.md index 63d6665d8..f95eabc3d 100644 --- a/snippet-template.md +++ b/snippet-template.md @@ -8,4 +8,4 @@ Explain briefly how the snippet works. const functionName = arguments => {functionBody} // functionName(sampleInput) -> sampleOutput -``` +``` \ No newline at end of file diff --git a/snippets/primes.md b/snippets/primes.md new file mode 100644 index 000000000..31dafc045 --- /dev/null +++ b/snippets/primes.md @@ -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] +``` \ No newline at end of file