From 06c4a01fcfae88a70127ad011b2a095f40bd9c02 Mon Sep 17 00:00:00 2001 From: hhow09 Date: Thu, 23 Jan 2025 12:32:48 +0100 Subject: [PATCH] doc: update document --- README.md | 6 +++++- backend/README.md | 22 +++++++++++++++++++++- frontend/README.md | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6c9c99e..56a07a0 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,8 @@ link when you’re done. 8. Split it up into a frontend and a backend (use the MERN stack) 9. Using typescript will be a bonus. 10. Please avoid using the eval-cmd of the JS math library -11. The more effort you put into it (e.g. design wise, documentation wise) the better the rating will be. \ No newline at end of file +11. The more effort you put into it (e.g. design wise, documentation wise) the better the rating will be. + +## How to start +1. follow the instructions in [backend/README.md](backend/README.md#run-at-local) to start backend server +2. follow the instructions in [frontend/README.md](frontend/README.md#run-at-local) to start frontend diff --git a/backend/README.md b/backend/README.md index 2686043..468854e 100644 --- a/backend/README.md +++ b/backend/README.md @@ -16,7 +16,27 @@ npm run start npm run test ``` -## Limitations on calculation +## Features +- [x] It supports 2 types of operations requested via websocket + - `operation`: evaluate an expression and return the result. + - `history`: get the latest 10 commands and results. +- [x] [Express](https://expressjs.com/) is used for the server and router. +- [x] [Socket.io](https://socket.io/) is used for WebSocket communication. +- [x] [MongoDB](https://www.mongodb.com/) is used for storing chat history. + - [Array $slice](https://www.mongodb.com/docs/manual/reference/operator/update/slice/) is used to keep only the latest history. +- [x] [Jest](https://jestjs.io/) is used for unit testing. +- [x] [Github Workflows](../.github/workflows/ci.yaml) is used for continuous integration. + +## Math Calculation +### Evalutaion Algorithm +1. Parse the expression string by splitting by `+` and `-`, resulting a list of sub-expressions (`ExpressionMD`). +2. For each sub-expression, turn it into a `Fraction`. +3. Sum all fractions by `Fraction.add(Fraction)`. + - It uses **lowest common multiple** to add fractions. + - [Decimal.js](https://mikemcl.github.io/decimal.js/) is used for the basic arithmetic operations. +4. Evaluate the result by `Fraction.evaluate()`. + +### Limitations - All whitespace is ignored, therefore `1 + 2 3` will consider as `1 + 23` - `negative sign` is only allowed at the beginning of an expression but not after multiplication or division - e.g. `-5*3 + 1` will return `-14` diff --git a/frontend/README.md b/frontend/README.md index 16ee068..9fc03dc 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -6,7 +6,7 @@ npm install cp .env.example .env # modify as needed ``` -## Start Locally +## Run at Local ``` npm run build npm run preview