Created
April 4, 2018 09:02
-
-
Save mykeels/8396f87d42a809697d08f6b6c9cd8db0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const isPrime = require('./is-prime') | |
const app = express() | |
app.get('/', (req, res) => { | |
const primes = [] | |
const max = Number(req.query.max) || 1000 | |
for (let i = 1; i <= max; i++) { | |
if (isPrime(i)) primes.push(i) | |
} | |
res.json(primes) | |
}) | |
app.listen(process.env.PORT || 3030) | |
console.log('app is running!') | |
module.exports = app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (num) => { | |
if ([2, 3].indexOf(num) >= 0) return true; | |
else if ([2, 3].some(n => num % n == 0)) return false; | |
else { | |
let i = 5, w = 2; | |
while ((i * i) <= num) { | |
if (num % i == 0) return false | |
i += w | |
w = 6 - w | |
} | |
} | |
return true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "prime-cluster", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node index" | |
}, | |
"author": "", | |
"license": "MIT", | |
"dependencies": { | |
"express": "^4.16.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment