Files
stupid-apis/src/routes/api/sorts/sleepSort.js
T
johannesbot 19c477aa05
Build and Deploy / build (push) Successful in 1m44s
Build Release / build (push) Successful in 58s
Build and Deploy / deploy (push) Successful in 26s
12 new API endpoints
2026-06-16 20:51:18 +02:00

22 lines
555 B
JavaScript

const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input)) {
return res.status(400).json({ error: 'input must be an array' });
}
const sorted = [...input].sort((a, b) => a - b);
const totalSleepMs = input.reduce((sum, n) => sum + Math.abs(Number(n)), 0);
res.json({
ret: sorted,
totalSleepTimeMs: totalSleepMs,
note: "We simulated the sleep. You're welcome."
});
});
module.exports = router;