Skip to content

Commit 06c4a01

Browse files
committed
doc: update document
1 parent 26239ae commit 06c4a01

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Diff for: README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ link when you’re done.
1616
8. Split it up into a frontend and a backend (use the MERN stack)
1717
9. Using typescript will be a bonus.
1818
10. Please avoid using the eval-cmd of the JS math library
19-
11. The more effort you put into it (e.g. design wise, documentation wise) the better the rating will be.
19+
11. The more effort you put into it (e.g. design wise, documentation wise) the better the rating will be.
20+
21+
## How to start
22+
1. follow the instructions in [backend/README.md](backend/README.md#run-at-local) to start backend server
23+
2. follow the instructions in [frontend/README.md](frontend/README.md#run-at-local) to start frontend

Diff for: backend/README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,27 @@ npm run start
1616
npm run test
1717
```
1818

19-
## Limitations on calculation
19+
## Features
20+
- [x] It supports 2 types of operations requested via websocket
21+
- `operation`: evaluate an expression and return the result.
22+
- `history`: get the latest 10 commands and results.
23+
- [x] [Express](https://expressjs.com/) is used for the server and router.
24+
- [x] [Socket.io](https://socket.io/) is used for WebSocket communication.
25+
- [x] [MongoDB](https://www.mongodb.com/) is used for storing chat history.
26+
- [Array $slice](https://www.mongodb.com/docs/manual/reference/operator/update/slice/) is used to keep only the latest history.
27+
- [x] [Jest](https://jestjs.io/) is used for unit testing.
28+
- [x] [Github Workflows](../.github/workflows/ci.yaml) is used for continuous integration.
29+
30+
## Math Calculation
31+
### Evalutaion Algorithm
32+
1. Parse the expression string by splitting by `+` and `-`, resulting a list of sub-expressions (`ExpressionMD`).
33+
2. For each sub-expression, turn it into a `Fraction`.
34+
3. Sum all fractions by `Fraction.add(Fraction)`.
35+
- It uses **lowest common multiple** to add fractions.
36+
- [Decimal.js](https://mikemcl.github.io/decimal.js/) is used for the basic arithmetic operations.
37+
4. Evaluate the result by `Fraction.evaluate()`.
38+
39+
### Limitations
2040
- All whitespace is ignored, therefore `1 + 2 3` will consider as `1 + 23`
2141
- `negative sign` is only allowed at the beginning of an expression but not after multiplication or division
2242
- e.g. `-5*3 + 1` will return `-14`

Diff for: frontend/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ npm install
66
cp .env.example .env # modify as needed
77
```
88

9-
## Start Locally
9+
## Run at Local
1010
```
1111
npm run build
1212
npm run preview

0 commit comments

Comments
 (0)