For this technical test I had to create a simple calculator in javascript in the console.
- Do not use eval() function.
- Define a development approach.
- Make an optimized and commented source code.
- Do a demo of the application.
- Explain application's details.
- Support subexpression - (21 + 14) * 2
Do an app that return the result of an operation such as :
A [+, -, *, /] B
21 + 14
= 35
Server: Node
Test: Jest
Source code has been commented throughout the application.
- Readline (a native node module)
- Nodemon
- Jest
git clone https://github.com/davidfaure/testUbiwan
cd testUbiwan
npm install
npm start
To run tests, run the following command
npm run test
- import readline and create an interface to read user input inside console
- ask user for an operation
- coding the logic inside calculator function
- Remove white space if any.
- Create an array of every single string typed by user.
- Check if the array contain at least a number, return false if not.
- Check if the array contain a valid operator, return false if not.
- Check if at least 2 number are typed to do at least a simple operation.
- Join number inside array before and after the operator.
- Calculate the operation and return the result.
David Faure - Portfolio
David Faure - GitHub