Build a NodeJS Rest API with ExpressJS. It should be a POST endpoint that is going to get these parameters:
- minNumber (Should be greater than 0 )
- maxNumber
- feature (should be an array: [“palindrome”, “prime”]) The API should Return:
- data (array) should contain all the numbers that are palindromes or primes or that are palindromes and primes at the same time based on the feature parameter.
- timeOfExecution: (float) time of how long it took to get the results This task should be runnable locally and pushed to a git repository Make sure you add validations for the endpoint parameters.
- Node.js v16.2.0 and NPM v8.3.1
To run this project ensure you have nodejs installed on your system Find instructions on the Node.js documentation
-
Clone the repo
git clone https://github.com/wamaithanyamu/backendTaskHorizontLabs.git
-
Navigate to the project foldler
cd backendTaskHorizontLabs
-
Install NPM packages
npm install
-
Run server
npm start
-
Run tests using
npm test
You can test the endpoint using postman as shown below
The prime numbers algorithm used is the Sieve of Eratosthenes which has a complexity of n*log(log(n)) The palindrome algorithm has a complexity of O(n). However, the algorithm has been sped up by comparing two halves of a number instead of comparing two strings.
The space complexity for both algorithms is O(N) since the space occupied depends on the range of numbers we need to compute.
Distributed under the MIT License. See LICENSE.txt
for more information.