Skip to content

wamaithaNyamu/backendTaskHorizontLabs

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn

Task description

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.

Built With

(back to top)

Getting Started

To run this project ensure you have nodejs installed on your system Find instructions on the Node.js documentation

Installation

  1. Clone the repo

    git clone https://github.com/wamaithanyamu/backendTaskHorizontLabs.git
  2. Navigate to the project foldler

    cd backendTaskHorizontLabs
    
  3. Install NPM packages

    npm install
  4. Run server

    npm start
  5. Run tests using

    npm test

(back to top)

Usage

You can test the endpoint using postman as shown below

Big O and space compelxity

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.

License

Distributed under the MIT License. See LICENSE.txt for more information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published