Infite loops module makes possible to render infinite rectangles of a given height and width and recursively create inner rectangles of same height - padding and width - padding until there is no space left in the last shape.
Project will work with Node of version 10 or higher. There on other dependencies.
- Install
Nodeif needed. Installer is available at https://nodejs.org/en/download/. - Open a command line.
- Clone this repository. Command
git clone https://github.com/CodeVoyager/infinite-shapes.git cd infinite-shapes
This module can be used as a required module or from command line.
Module can be treated as just another module existing on your device's hard drive. It can be required like any other module with const infiniteLoops = require('<relative_path>/infinite-loops').
Module exports methods:
draw(width: number, height: number, padding: number): number[][]- Infite loop represented with an array of arrays of numbersdrawToString(arr: number[][]): string- Result of draw method represented as string. Characters mapped from number to characters. Rows separated with\n.handleRequest({ action: string, width: number, height: number, padding: number }): {isOk: boolean, value: any, err: Error}- Facade function for module. Accept action name and action parameters and returs Result object. If action is successfulisOkis true and value is present. Otherwise value is not set anderrattribute contains reason of failure.
Available actions are:
node index.js draw <width> <height> <padding>- Infite loop represented with an array of arrays of numbersnode index.js print <width> <height> <padding>- Infite loop represented as string.
- Width should be even and >=20
- Height should be even and >=20
- Padding should be even and >=4
You can use npm scripts below to run tests
npm run test- Runs all testnpm run test:index- Runs test for index modulenpm run test:draw- Runs test for draw modulenpm run test:draw -- <path_to_test_cases/file.json>- Runs test for draw module with user defined test data.
Test data should be file with JSON standard compliant content. Data format:
[
{
"input": "<width>,<height>,<padding>", // input
"pixelArrayJson": "[[0, 0, 0]]", // number[][] passed into JSON.stringify
}
]
Space complexity is O(N + M) where N and M are dimensions of outer rectangle
Time complexity is O(n)
Goal of this project is to be have as little dendecies as possible. Testing and some API elements are therefore simplified.


