Creative Cash Draw Solutions is a client who wants to provide something different for the cashiers who use their system. The function of the application is to tell the cashier how much change is owed, and what denominations should be used. In most cases, the app should return the minimum amount of physical change, but the client would like to add a twist. If the "owed" amount is divisible by 3, the app should randomly generate the change denominations (but the math still needs to be right :))
Please write a program which accomplishes the client's goals. The program should:
- Accept a flat file as input
- Each line will contain the amount owed and the amount paid separated by a comma (for example: 2.13,3.00)
- Expect that there will be multiple lines
- Output the change the cashier should return to the customer
- The return string should look like: 1 dollar,2 quarters,1 nickel, etc ...
- Each new line in the input file should be a new line in the output file
2.12,3.00
1.97,2.00
3.33,5.00
3 quarters,1 dime,3 pennies
3 pennies
1 dollar,1 quarter,6 nickels,12 pennies
Remember the last one is random
Please use whatever technology and techniques you feel are applicable to solve the problem. We suggest that you approach this exercise as if this code was part of a larger system. The end result should be representative of your abilities and style.
Please fork this repository. When you have completed your solution, please issue a pull request to notify us that you are ready.
Have fun.
Here are a couple of thoughts about the domain that could influence your response:
- What might happen if the client needs to change the random divisor?
- What might happen if the client needs to add another special case (like the random twist)?
- What might happen if sales closes a new client in France?
To successfully run the application, ensure you have the following dependencies installed:
-
Node.js: The runtime environment for running JavaScript server-side.
-
Docker: Required to build and run Docker containers.
-
Docker Compose: Used to define and run multi-container Docker applications.
-
Knex: SQL query builder used in the backend.
- Install Knex globally
- Install locally within the project:
npm install knex
-
PostgreSQL: Database management system used for storing data. (If testing without Docker)
To build and run the application using Docker, follow these steps:
-
Build and Start Docker Containers
Run the following command from the root of the project:
npm run docker:up
This command will:
- Build Docker images for both the client and server.
- Start Docker containers for both the client and server.
- Ensure that the application is accessible at http://localhost:3000 for the client and http://localhost:3001 for the server.
-
Access the Application
Open your browser and go to http://localhost:3000 to access the client application. The server will be running at http://localhost:3001 and will handle API requests from the client.
If you prefer to run the application locally without Docker, follow these steps:
-
Install Dependencies
Ensure you have all the necessary local dependencies installed by running:
npm install
-
Database Setup
Make sure you have a PostgreSQL database running and configured. Update the .env file with your database credentials or configure them directly in your application.
-
Run the Server
Navigate to the server directory and start the server:
npm run start:server
-
Run the Client
Navigate to the client directory, and start the client:
npm run start:client
-
Access the Application
Open your browser and go to http://localhost:3000 to access the client application. The server will be running at http://localhost:3001 and will handle API requests from the client.
To ensure code quality and consistency, run the linter using:
npm run lintTo run the tests for the application, use:
npm run testBy following these steps, you should be able to run and test the application both locally and within Docker containers. If you have any questions, feel free to reach out!