This project was bootstrapped with Create React App.
This project has been created using create-react-app
with the --use-pnp
option; before running it, be sure to create a .pnp
folder with the required files from the necessary packages running
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You can use the calculator in a similar way to how you would use a pocket calculator; in case or 'Error' please reset the calculator pressing 'CE'
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
With more time available, I would definitely consider:
- expanding/improving the test coverage;
- improve CSS with some CSS-compiler (SCSS, LESS or other option);
- implementing better handling of calculator-like functionalities (after pressing
=
for example any number should reset the display, not add to that), possibly changing the state to keep track of both the current expression and the last key pressed; - dynamically handling the size of the display text to go on 2 lines when there are more than X characters;
- preventing users from typing blatantly wrong syntax (closed parentheses before a greater or equal number of open parenthesis, no more than one
.
per number, etc); - avoiding to use
eval
to compute a result withevaluateExpression
- as they say: "eval is evil"; - ideally replacing it with a parsing function that moves singling out elements in parenthesis, recursively calling itself to extracts numbers and operators and to compute the result of it;
- better error handling (currently we just display "Error" in any case, be it a division by zero, a missing parenthesis, etc)
- support for other insert operators (exponentiaion, modulo);
- support for non-insert operators (logarithm, abs).