From 56bd3ea60421bff2e2e38d9dfdf540d035e9ae2f Mon Sep 17 00:00:00 2001 From: JohannesBOT Date: Wed, 17 Jun 2026 06:24:22 +0200 Subject: [PATCH] 20 new API endpoints --- src/routes/api/array/arrayMax.js | 11 + src/routes/api/array/arrayMin.js | 11 + src/routes/api/array/arrayUnique.js | 10 + src/routes/api/array/average.js | 11 + src/routes/api/array/sum.js | 10 + src/routes/api/index.js | 22 + src/routes/api/math/abs.js | 13 + src/routes/api/math/factorial.js | 23 + src/routes/api/math/isPrime.js | 23 + src/routes/api/math/power.js | 13 + src/routes/api/misc/coinFlip.js | 8 + src/routes/api/misc/diceRoll.js | 13 + src/routes/api/misc/fizzBuzz.js | 20 + src/routes/api/sorts/gnomeSort.js | 25 + src/routes/api/sorts/intelligentDesignSort.js | 13 + src/routes/api/sorts/pancakeSort.js | 35 ++ src/routes/api/sorts/quantumSort.js | 15 + src/routes/api/string/randomCase.js | 19 + src/routes/api/string/repeat.js | 10 + src/routes/api/string/stringContains.js | 9 + src/routes/api/string/trimString.js | 13 + src/routes/docs/openapi.json | 529 ++++++++++++++++++ 22 files changed, 856 insertions(+) create mode 100644 src/routes/api/array/arrayMax.js create mode 100644 src/routes/api/array/arrayMin.js create mode 100644 src/routes/api/array/arrayUnique.js create mode 100644 src/routes/api/array/average.js create mode 100644 src/routes/api/array/sum.js create mode 100644 src/routes/api/math/abs.js create mode 100644 src/routes/api/math/factorial.js create mode 100644 src/routes/api/math/isPrime.js create mode 100644 src/routes/api/math/power.js create mode 100644 src/routes/api/misc/coinFlip.js create mode 100644 src/routes/api/misc/diceRoll.js create mode 100644 src/routes/api/misc/fizzBuzz.js create mode 100644 src/routes/api/sorts/gnomeSort.js create mode 100644 src/routes/api/sorts/intelligentDesignSort.js create mode 100644 src/routes/api/sorts/pancakeSort.js create mode 100644 src/routes/api/sorts/quantumSort.js create mode 100644 src/routes/api/string/randomCase.js create mode 100644 src/routes/api/string/repeat.js create mode 100644 src/routes/api/string/stringContains.js create mode 100644 src/routes/api/string/trimString.js diff --git a/src/routes/api/array/arrayMax.js b/src/routes/api/array/arrayMax.js new file mode 100644 index 0000000..602a3df --- /dev/null +++ b/src/routes/api/array/arrayMax.js @@ -0,0 +1,11 @@ +const express = require('express'); +const router = express.Router(); + +router.post('/', (req, res) => { + const { input } = req.body; + if (!Array.isArray(input) || input.length === 0) + return res.status(400).json({ error: 'input must be a non-empty array' }); + res.json({ ret: Math.max(...input.map(Number)) }); +}); + +module.exports = router; diff --git a/src/routes/api/array/arrayMin.js b/src/routes/api/array/arrayMin.js new file mode 100644 index 0000000..f5598be --- /dev/null +++ b/src/routes/api/array/arrayMin.js @@ -0,0 +1,11 @@ +const express = require('express'); +const router = express.Router(); + +router.post('/', (req, res) => { + const { input } = req.body; + if (!Array.isArray(input) || input.length === 0) + return res.status(400).json({ error: 'input must be a non-empty array' }); + res.json({ ret: Math.min(...input.map(Number)) }); +}); + +module.exports = router; diff --git a/src/routes/api/array/arrayUnique.js b/src/routes/api/array/arrayUnique.js new file mode 100644 index 0000000..4c0ec1e --- /dev/null +++ b/src/routes/api/array/arrayUnique.js @@ -0,0 +1,10 @@ +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' }); + res.json({ ret: [...new Set(input)] }); +}); + +module.exports = router; diff --git a/src/routes/api/array/average.js b/src/routes/api/array/average.js new file mode 100644 index 0000000..8643e92 --- /dev/null +++ b/src/routes/api/array/average.js @@ -0,0 +1,11 @@ +const express = require('express'); +const router = express.Router(); + +router.post('/', (req, res) => { + const { input } = req.body; + if (!Array.isArray(input) || input.length === 0) + return res.status(400).json({ error: 'input must be a non-empty array' }); + res.json({ ret: input.reduce((acc, n) => acc + Number(n), 0) / input.length }); +}); + +module.exports = router; diff --git a/src/routes/api/array/sum.js b/src/routes/api/array/sum.js new file mode 100644 index 0000000..b45fa7f --- /dev/null +++ b/src/routes/api/array/sum.js @@ -0,0 +1,10 @@ +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' }); + res.json({ ret: input.reduce((acc, n) => acc + Number(n), 0) }); +}); + +module.exports = router; diff --git a/src/routes/api/index.js b/src/routes/api/index.js index bb8aa7c..ee2c53d 100644 --- a/src/routes/api/index.js +++ b/src/routes/api/index.js @@ -7,6 +7,10 @@ router.use('/subtract', require('./math/subtract')); router.use('/multiply', require('./math/multiply')); router.use('/divide', require('./math/divide')); router.use('/modulo', require('./math/modulo')); +router.use('/power', require('./math/power')); +router.use('/abs', require('./math/abs')); +router.use('/factorial', require('./math/factorial')); +router.use('/isPrime', require('./math/isPrime')); // String router.use('/toString', require('./string/toString')); @@ -17,21 +21,39 @@ router.use('/stringLength', require('./string/stringLength')); router.use('/countWords', require('./string/countWords')); router.use('/toUpperCase', require('./string/toUpperCase')); router.use('/toLowerCase', require('./string/toLowerCase')); +router.use('/repeat', require('./string/repeat')); +router.use('/trimString', require('./string/trimString')); +router.use('/stringContains', require('./string/stringContains')); +router.use('/randomCase', require('./string/randomCase')); // Array router.use('/sort', require('./array/sort')); router.use('/reverseArray', require('./array/reverseArray')); +router.use('/sum', require('./array/sum')); +router.use('/average', require('./array/average')); +router.use('/arrayMax', require('./array/arrayMax')); +router.use('/arrayMin', require('./array/arrayMin')); +router.use('/arrayUnique', require('./array/arrayUnique')); // Checks router.use('/isEven', require('./checks/isEven')); router.use('/isOdd', require('./checks/isOdd')); router.use('/isNumber', require('./checks/isNumber')); +// Misc +router.use('/coinFlip', require('./misc/coinFlip')); +router.use('/diceRoll', require('./misc/diceRoll')); +router.use('/fizzBuzz', require('./misc/fizzBuzz')); + // Meme sorts router.use('/stalinSort', require('./sorts/stalinSort')); router.use('/bogoSort', require('./sorts/bogoSort')); router.use('/thanoSort', require('./sorts/thanoSort')); router.use('/sleepSort', require('./sorts/sleepSort')); router.use('/miracleSort', require('./sorts/miracleSort')); +router.use('/intelligentDesignSort', require('./sorts/intelligentDesignSort')); +router.use('/quantumSort', require('./sorts/quantumSort')); +router.use('/pancakeSort', require('./sorts/pancakeSort')); +router.use('/gnomeSort', require('./sorts/gnomeSort')); module.exports = router; diff --git a/src/routes/api/math/abs.js b/src/routes/api/math/abs.js new file mode 100644 index 0000000..b61ca3b --- /dev/null +++ b/src/routes/api/math/abs.js @@ -0,0 +1,13 @@ +const express = require('express'); +const router = express.Router(); + +router.post('/', (req, res) => { + const { input } = req.body; + res.json({ ret: Math.abs(Number(input)) }); +}); + +router.get('/:n', (req, res) => { + res.json({ ret: Math.abs(Number(req.params.n)) }); +}); + +module.exports = router; diff --git a/src/routes/api/math/factorial.js b/src/routes/api/math/factorial.js new file mode 100644 index 0000000..a337fb9 --- /dev/null +++ b/src/routes/api/math/factorial.js @@ -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; diff --git a/src/routes/api/math/isPrime.js b/src/routes/api/math/isPrime.js new file mode 100644 index 0000000..73882a0 --- /dev/null +++ b/src/routes/api/math/isPrime.js @@ -0,0 +1,23 @@ +const express = require('express'); +const router = express.Router(); + +function isPrime(n) { + if (n < 2) return false; + if (n === 2) return true; + if (n % 2 === 0) return false; + for (let i = 3; i <= Math.sqrt(n); i += 2) { + if (n % i === 0) return false; + } + return true; +} + +router.post('/', (req, res) => { + const { input } = req.body; + res.json({ ret: isPrime(Math.floor(Number(input))) }); +}); + +router.get('/:n', (req, res) => { + res.json({ ret: isPrime(Math.floor(Number(req.params.n))) }); +}); + +module.exports = router; diff --git a/src/routes/api/math/power.js b/src/routes/api/math/power.js new file mode 100644 index 0000000..bd329c8 --- /dev/null +++ b/src/routes/api/math/power.js @@ -0,0 +1,13 @@ +const express = require('express'); +const router = express.Router(); + +router.post('/', (req, res) => { + const { input } = req.body; + res.json({ ret: Math.pow(input.a, input.b) }); +}); + +router.get('/:a/:b', (req, res) => { + res.json({ ret: Math.pow(Number(req.params.a), Number(req.params.b)) }); +}); + +module.exports = router; diff --git a/src/routes/api/misc/coinFlip.js b/src/routes/api/misc/coinFlip.js new file mode 100644 index 0000000..c95f8d4 --- /dev/null +++ b/src/routes/api/misc/coinFlip.js @@ -0,0 +1,8 @@ +const express = require('express'); +const router = express.Router(); + +router.get('/', (req, res) => { + res.json({ ret: Math.random() < 0.5 ? 'heads' : 'tails' }); +}); + +module.exports = router; diff --git a/src/routes/api/misc/diceRoll.js b/src/routes/api/misc/diceRoll.js new file mode 100644 index 0000000..79000c3 --- /dev/null +++ b/src/routes/api/misc/diceRoll.js @@ -0,0 +1,13 @@ +const express = require('express'); +const router = express.Router(); + +router.get('/', (req, res) => { + res.json({ ret: Math.floor(Math.random() * 6) + 1 }); +}); + +router.get('/:sides', (req, res) => { + const sides = Math.max(2, Math.floor(Number(req.params.sides))); + res.json({ ret: Math.floor(Math.random() * sides) + 1, sides }); +}); + +module.exports = router; diff --git a/src/routes/api/misc/fizzBuzz.js b/src/routes/api/misc/fizzBuzz.js new file mode 100644 index 0000000..a497b1b --- /dev/null +++ b/src/routes/api/misc/fizzBuzz.js @@ -0,0 +1,20 @@ +const express = require('express'); +const router = express.Router(); + +function fizzBuzz(n) { + if (n % 15 === 0) return 'FizzBuzz'; + if (n % 3 === 0) return 'Fizz'; + if (n % 5 === 0) return 'Buzz'; + return n; +} + +router.post('/', (req, res) => { + const { input } = req.body; + res.json({ ret: fizzBuzz(Number(input)) }); +}); + +router.get('/:n', (req, res) => { + res.json({ ret: fizzBuzz(Number(req.params.n)) }); +}); + +module.exports = router; diff --git a/src/routes/api/sorts/gnomeSort.js b/src/routes/api/sorts/gnomeSort.js new file mode 100644 index 0000000..a4151b2 --- /dev/null +++ b/src/routes/api/sorts/gnomeSort.js @@ -0,0 +1,25 @@ +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 arr = [...input]; + let pos = 0; + let moves = 0; + + while (pos < arr.length) { + if (pos === 0 || arr[pos] >= arr[pos - 1]) { + pos++; + } else { + [arr[pos], arr[pos - 1]] = [arr[pos - 1], arr[pos]]; + pos--; + moves++; + } + } + + res.json({ ret: arr, moves }); +}); + +module.exports = router; diff --git a/src/routes/api/sorts/intelligentDesignSort.js b/src/routes/api/sorts/intelligentDesignSort.js new file mode 100644 index 0000000..55886d5 --- /dev/null +++ b/src/routes/api/sorts/intelligentDesignSort.js @@ -0,0 +1,13 @@ +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' }); + res.json({ + ret: input, + message: 'The array has been sorted by a higher power. Who are we to question it?' + }); +}); + +module.exports = router; diff --git a/src/routes/api/sorts/pancakeSort.js b/src/routes/api/sorts/pancakeSort.js new file mode 100644 index 0000000..d0fd514 --- /dev/null +++ b/src/routes/api/sorts/pancakeSort.js @@ -0,0 +1,35 @@ +const express = require('express'); +const router = express.Router(); + +function flip(arr, k) { + let left = 0; + while (left < k) { + [arr[left], arr[k]] = [arr[k], arr[left]]; + left++; + k--; + } +} + +router.post('/', (req, res) => { + const { input } = req.body; + if (!Array.isArray(input)) return res.status(400).json({ error: 'input must be an array' }); + + const arr = [...input]; + const flips = []; + + for (let size = arr.length; size > 1; size--) { + const maxIdx = arr.slice(0, size).indexOf(Math.max(...arr.slice(0, size))); + if (maxIdx !== size - 1) { + if (maxIdx !== 0) { + flip(arr, maxIdx); + flips.push(maxIdx + 1); + } + flip(arr, size - 1); + flips.push(size); + } + } + + res.json({ ret: arr, flips, totalFlips: flips.length }); +}); + +module.exports = router; diff --git a/src/routes/api/sorts/quantumSort.js b/src/routes/api/sorts/quantumSort.js new file mode 100644 index 0000000..d2ad580 --- /dev/null +++ b/src/routes/api/sorts/quantumSort.js @@ -0,0 +1,15 @@ +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' }); + res.json({ + ret: [...input].sort((a, b) => a - b), + universeCollapsed: true, + parallelUniversesDestroyed: Math.pow(2, input.length), + message: 'Wave function collapsed successfully. All other quantum states have been discarded.' + }); +}); + +module.exports = router; diff --git a/src/routes/api/string/randomCase.js b/src/routes/api/string/randomCase.js new file mode 100644 index 0000000..70c0976 --- /dev/null +++ b/src/routes/api/string/randomCase.js @@ -0,0 +1,19 @@ +const express = require('express'); +const router = express.Router(); + +function randomCase(str) { + return String(str).split('').map(c => + Math.random() > 0.5 ? c.toUpperCase() : c.toLowerCase() + ).join(''); +} + +router.post('/', (req, res) => { + const { input } = req.body; + res.json({ ret: randomCase(input) }); +}); + +router.get('/:string', (req, res) => { + res.json({ ret: randomCase(req.params.string) }); +}); + +module.exports = router; diff --git a/src/routes/api/string/repeat.js b/src/routes/api/string/repeat.js new file mode 100644 index 0000000..b0342ce --- /dev/null +++ b/src/routes/api/string/repeat.js @@ -0,0 +1,10 @@ +const express = require('express'); +const router = express.Router(); + +router.post('/', (req, res) => { + const { input } = req.body; + const times = Math.min(Math.max(0, Math.floor(Number(input.times))), 1000); + res.json({ ret: String(input.string).repeat(times) }); +}); + +module.exports = router; diff --git a/src/routes/api/string/stringContains.js b/src/routes/api/string/stringContains.js new file mode 100644 index 0000000..7b0b06f --- /dev/null +++ b/src/routes/api/string/stringContains.js @@ -0,0 +1,9 @@ +const express = require('express'); +const router = express.Router(); + +router.post('/', (req, res) => { + const { input } = req.body; + res.json({ ret: String(input.string).includes(String(input.search)) }); +}); + +module.exports = router; diff --git a/src/routes/api/string/trimString.js b/src/routes/api/string/trimString.js new file mode 100644 index 0000000..c35a5e3 --- /dev/null +++ b/src/routes/api/string/trimString.js @@ -0,0 +1,13 @@ +const express = require('express'); +const router = express.Router(); + +router.post('/', (req, res) => { + const { input } = req.body; + res.json({ ret: String(input).trim() }); +}); + +router.get('/:string', (req, res) => { + res.json({ ret: req.params.string.trim() }); +}); + +module.exports = router; diff --git a/src/routes/docs/openapi.json b/src/routes/docs/openapi.json index 18db2bd..2148c02 100644 --- a/src/routes/docs/openapi.json +++ b/src/routes/docs/openapi.json @@ -20,6 +20,7 @@ { "name": "String", "description": "String manipulation" }, { "name": "Array", "description": "Array operations" }, { "name": "Checks", "description": "Value checking" }, + { "name": "Misc", "description": "Miscellaneous fun endpoints" }, { "name": "Sorts", "description": "Sorting algorithms (serious and meme)" } ], "paths": { @@ -718,6 +719,534 @@ } } } + }, + "/power": { + "post": { + "tags": ["Math"], + "summary": "Raises a to the power of b (a^b)", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { + "type": "object", + "properties": { + "a": { "type": "number", "example": 2 }, + "b": { "type": "number", "example": 8 } + } + } + } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/power/{a}/{b}": { + "get": { + "tags": ["Math"], + "summary": "Raises a to the power of b from path parameters", + "parameters": [ + { "name": "a", "in": "path", "required": true, "schema": { "type": "string" }, "example": "2" }, + { "name": "b", "in": "path", "required": true, "schema": { "type": "string" }, "example": "8" } + ], + "responses": { "200": { "description": "Success" } } + } + }, + "/abs": { + "post": { + "tags": ["Math"], + "summary": "Returns the absolute value of a number", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { "input": { "type": "number", "example": -42 } } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/abs/{n}": { + "get": { + "tags": ["Math"], + "summary": "Returns the absolute value from path parameter", + "parameters": [ + { "name": "n", "in": "path", "required": true, "schema": { "type": "string" }, "example": "-42" } + ], + "responses": { "200": { "description": "Success" } } + } + }, + "/factorial": { + "post": { + "tags": ["Math"], + "summary": "Calculates n! (0–170)", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { "input": { "type": "number", "example": 5 } } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/factorial/{n}": { + "get": { + "tags": ["Math"], + "summary": "Calculates n! from path parameter", + "parameters": [ + { "name": "n", "in": "path", "required": true, "schema": { "type": "string" }, "example": "5" } + ], + "responses": { "200": { "description": "Success" } } + } + }, + "/isPrime": { + "post": { + "tags": ["Math"], + "summary": "Checks if a number is prime", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { "input": { "type": "number", "example": 17 } } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/isPrime/{n}": { + "get": { + "tags": ["Math"], + "summary": "Checks if a number is prime from path parameter", + "parameters": [ + { "name": "n", "in": "path", "required": true, "schema": { "type": "string" }, "example": "17" } + ], + "responses": { "200": { "description": "Success" } } + } + }, + "/repeat": { + "post": { + "tags": ["String"], + "summary": "Repeats a string n times (max 1000)", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { + "type": "object", + "properties": { + "string": { "type": "string", "example": "ha" }, + "times": { "type": "number", "example": 3 } + } + } + } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/trimString": { + "post": { + "tags": ["String"], + "summary": "Trims leading and trailing whitespace from a string", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { "input": { "type": "string", "example": " hello " } } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/trimString/{string}": { + "get": { + "tags": ["String"], + "summary": "Trims whitespace from path parameter", + "parameters": [ + { "name": "string", "in": "path", "required": true, "schema": { "type": "string" } } + ], + "responses": { "200": { "description": "Success" } } + } + }, + "/stringContains": { + "post": { + "tags": ["String"], + "summary": "Checks if a string contains a substring", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { + "type": "object", + "properties": { + "string": { "type": "string", "example": "hello world" }, + "search": { "type": "string", "example": "world" } + } + } + } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/randomCase": { + "post": { + "tags": ["String"], + "summary": "Randomly capitalizes letters (sPoNgEbOb CaSe)", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { "input": { "type": "string", "example": "mocking spongebob" } } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/randomCase/{string}": { + "get": { + "tags": ["String"], + "summary": "Randomly capitalizes letters from path parameter", + "parameters": [ + { "name": "string", "in": "path", "required": true, "schema": { "type": "string" }, "example": "hello" } + ], + "responses": { "200": { "description": "Success" } } + } + }, + "/sum": { + "post": { + "tags": ["Array"], + "summary": "Sums all elements of an array", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { "type": "array", "items": { "type": "number" }, "example": [1, 2, 3, 4, 5] } + } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/average": { + "post": { + "tags": ["Array"], + "summary": "Calculates the average of all elements in an array", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { "type": "array", "items": { "type": "number" }, "example": [1, 2, 3, 4, 5] } + } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/arrayMax": { + "post": { + "tags": ["Array"], + "summary": "Returns the largest element in an array", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { "type": "array", "items": { "type": "number" }, "example": [3, 1, 4, 1, 5, 9] } + } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/arrayMin": { + "post": { + "tags": ["Array"], + "summary": "Returns the smallest element in an array", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { "type": "array", "items": { "type": "number" }, "example": [3, 1, 4, 1, 5, 9] } + } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/arrayUnique": { + "post": { + "tags": ["Array"], + "summary": "Removes duplicate elements from an array", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { "type": "array", "items": {}, "example": [1, 2, 2, 3, 3, 3] } + } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/coinFlip": { + "get": { + "tags": ["Misc"], + "summary": "Flips a coin — returns heads or tails", + "responses": { "200": { "description": "heads or tails" } } + } + }, + "/diceRoll": { + "get": { + "tags": ["Misc"], + "summary": "Rolls a standard 6-sided dice", + "responses": { "200": { "description": "Number between 1 and 6" } } + } + }, + "/diceRoll/{sides}": { + "get": { + "tags": ["Misc"], + "summary": "Rolls a dice with a custom number of sides", + "parameters": [ + { "name": "sides", "in": "path", "required": true, "schema": { "type": "string" }, "example": "20" } + ], + "responses": { "200": { "description": "Number between 1 and sides" } } + } + }, + "/fizzBuzz": { + "post": { + "tags": ["Misc"], + "summary": "Returns Fizz, Buzz, FizzBuzz or the number itself", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { "input": { "type": "number", "example": 15 } } + } + } + } + }, + "responses": { "200": { "description": "Success" } } + } + }, + "/fizzBuzz/{n}": { + "get": { + "tags": ["Misc"], + "summary": "FizzBuzz from path parameter", + "parameters": [ + { "name": "n", "in": "path", "required": true, "schema": { "type": "string" }, "example": "15" } + ], + "responses": { "200": { "description": "Success" } } + } + }, + "/intelligentDesignSort": { + "post": { + "tags": ["Sorts"], + "summary": "Sorts an array using Intelligent Design Sort", + "description": "The array is already perfectly sorted by a higher power. Who are we to question it?", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { "type": "array", "items": {}, "example": [3, 1, 4, 1, 5] } + } + } + } + } + }, + "responses": { + "200": { + "description": "The untouched array with a divine message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "ret": { "type": "array", "items": {} }, + "message": { "type": "string" } + } + } + } + } + } + } + } + }, + "/quantumSort": { + "post": { + "tags": ["Sorts"], + "summary": "Sorts an array using Quantum Sort", + "description": "Collapses the quantum superposition into the only sorted universe. All parallel universes with unsorted arrays are destroyed.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { "type": "array", "items": { "type": "number" }, "example": [3, 1, 4, 1, 5] } + } + } + } + } + }, + "responses": { + "200": { + "description": "Sorted array with quantum collapse metadata", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "ret": { "type": "array", "items": {} }, + "universeCollapsed": { "type": "boolean" }, + "parallelUniversesDestroyed": { "type": "number" }, + "message": { "type": "string" } + } + } + } + } + } + } + } + }, + "/pancakeSort": { + "post": { + "tags": ["Sorts"], + "summary": "Sorts an array using Pancake Sort", + "description": "Sorts by repeatedly flipping prefixes of the array, like flipping a stack of pancakes.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { "type": "array", "items": {}, "example": [3, 1, 4, 1, 5] } + } + } + } + } + }, + "responses": { + "200": { + "description": "Sorted array with flip history", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "ret": { "type": "array", "items": {} }, + "flips": { "type": "array", "items": { "type": "number" } }, + "totalFlips": { "type": "number" } + } + } + } + } + } + } + } + }, + "/gnomeSort": { + "post": { + "tags": ["Sorts"], + "summary": "Sorts an array using Gnome Sort", + "description": "A gnome sorts by looking at the current and previous flower pot. If they are in the wrong order, it swaps them and steps back.", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { "type": "array", "items": {}, "example": [3, 1, 4, 1, 5] } + } + } + } + } + }, + "responses": { + "200": { + "description": "Sorted array with move count", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "ret": { "type": "array", "items": {} }, + "moves": { "type": "number" } + } + } + } + } + } + } + } } } }