Created
April 12, 2021 15:22
-
-
Save adeyahya/e2fb4e86c278467a7aa3c16386ce052f 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 app = express(); | |
const cache = [0, 3]; | |
const getPi = (series = 0) => { | |
if (series === 0) return 3; | |
const middle = 4 * series; | |
const head = 4 / ((middle - 2) * (middle - 1) * middle); | |
const tail = 4 / (middle * (middle + 1) * (middle + 2)); | |
return head - tail; | |
}; | |
app.get("/", (_, res) => { | |
res.json({ | |
result: cache[1], | |
}); | |
cache[0] = cache[0] + 1; | |
cache[1] = cache[1] + getPi(cache[1]); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment