20 new API endpoints
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
function factorial(n) {
|
||||
if (n === 0 || n === 1) return 1;
|
||||
let result = 1;
|
||||
for (let i = 2; i <= n; i++) result *= i;
|
||||
return result;
|
||||
}
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const n = Math.floor(Number(req.body.input));
|
||||
if (n < 0 || n > 170) return res.status(400).json({ error: 'n must be between 0 and 170' });
|
||||
res.json({ ret: factorial(n) });
|
||||
});
|
||||
|
||||
router.get('/:n', (req, res) => {
|
||||
const n = Math.floor(Number(req.params.n));
|
||||
if (n < 0 || n > 170) return res.status(400).json({ error: 'n must be between 0 and 170' });
|
||||
res.json({ ret: factorial(n) });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user