Skip to content

Instantly share code, notes, and snippets.

@adeyahya
Created April 12, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeyahya/e2fb4e86c278467a7aa3c16386ce052f to your computer and use it in GitHub Desktop.
Save adeyahya/e2fb4e86c278467a7aa3c16386ce052f to your computer and use it in GitHub Desktop.
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