Tried to step out of my confort zone and attemped to complete this challenge using TypeScript.
Checking the Organisation Structure, quickly noticed that the best way to represent it was by using the Composite Design Pattern, with the Branch being the Leaf node and the other types (Area and Division) being a Composite node. Decided to split into different classes for SOC and scalability reasons.
As the main goal was to implement the calculateMembershipFee function, I implemented it on the index file. On a "real" app, I would have implemented it on a domain layer, along with the validations, and have separate layers for data and UI (multi-repo maybe?).
- Validate invalid Membership fees (negative or NaN).
- Mock organisation data and add calculateMembershipFee function tests.
- Move main function to a domain related folder along with the validations.
- Add simple UI to allow user interaction.
- Add the Client Organisation Unit (didn't add as it was not referred as an Organisation Unit in the challenge).
- Validate invalid function inputs (despite TypeScript already helping with that a bit).
This project uses node and npm.
$ npm install
To run tests:
$ npm run test
To compile and run an example:
$ npm run start
# it will compile to dist/ folder
BR | Description |
---|---|
BR1 | rent amount should be between 1 - int.max |
BR2 | rent period should be one of ["month", "week"] |
BR3 | calculate membership fee function should throw or return error when rent amount is invalid |
BR3.1 | allowed rent amount for week rent period should be [25£ ~ 2000£] |
BR3.2 | allowed rent amount for month rent period should be [110£ ~ 8660£] |
BR4 | monetary amounts are stored in pence |
PS: sorry for my english, I'm really looking forward to improve it!