Skip to content

Commit

Permalink
doc: update document
Browse files Browse the repository at this point in the history
  • Loading branch information
hhow09 committed Jan 23, 2025
1 parent 26239ae commit 06c4a01
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
22 changes: 21 additions & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ npm install
cp .env.example .env # modify as needed
```

## Start Locally
## Run at Local
```
npm run build
npm run preview
Expand Down

0 comments on commit 06c4a01

Please sign in to comment.