Git Product home page Git Product logo

infinite-recursive-shape's Introduction

Infinite recursive shape

The idea is to create a recursive function to draw boxes inside each other in array from 3 different variables width height and padding

Technology used

I used create react app for the UI and I used Jest for testing the function and travis for CI/CD I created 2 function for draw function in draw.js file I used different techniques for that one is recursion and the second solution is AB|CD or mirroring the array.

Installation

cd project directory, and run:

git clone [email protected]:schand143/infinite-recursive-shape.git cd infinite-recursive-shape npm install npm start

Testing

Test only run on the draw() function matching data from JSON file to check the value given toward the result of the function.

I created the function inside an object so I can run deep testing on it as recursive function calls itself directly it is not possible to spy on those calls since they refer directly to the function.

In order to spy on recursive calls they must refer to functions that can be spied on. Fortunately, this is possible by two ways either by wrapping the function inside object or by importing a recursive function back into its own module and use the imported function for the recursion

so I chooses the first option to run the jest.

to run the testing npm test

First Solution

The first solution I used Array.from to get the width of the array and the height of the array and then create every row in the array separately.

so the idea in any recursion function is to put the base case so my main base case is to check if the width and height less than or equal to zero then stop the function.

then checking on the height if it less than 2 draw the last row

then I have 2 returns after than the main one which will have the recursion after subtracting the padding after adding 2 to it to count the edges.

the the second return is happen only to draw the last box inside the array. you can see more details on the draw.js file.

The Big O

Screen shots

  1. Width: 40, Height:60, padding: 4)

Screen Shot 1

  1. (Width: 30, Height:50, padding: 6)

Screen Shot 2

  1. (Width: 40, Height:80, padding: 60)

Screen Shot 3

My Activities

infinite-recursive-shape's People

Contributors

schand143 avatar

Watchers

Mohamed Meabed avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.