Coder Social home page Coder Social logo

anmolshres / is-odd-code-generator-typescript Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 573 KB

Library to generate JavaScript code that can determine if a given number is odd

Home Page: https://www.npmjs.com/package/is-odd-code-generator

License: MIT License

JavaScript 0.01% TypeScript 100.00%

is-odd-code-generator-typescript's Introduction

is-odd-code-generator

CI NPM version NPM monthly downloads

Have you been looking for a npm package that can generate JavaScript code that can determine if a number is odd or not? Look no further. This package takes in a positive integer value, then generates JS code that can determine if a number is odd or not up to and including the supplied positive integer value.

Install

Install with npm:

npm install is-odd-code-generator

Usage

Only supports positive integers as input

import { generateIsOddCode } from 'is-odd-code-generator';

console.log(generateIsOddCode(-1)) // throws Error since the given number is negative

console.log(generateIsOddCode(0));
// returns:
// export function isOdd(number) {
//   if(number === 0) return false;
// }
console.log(generateIsOddCode(10));
// returns:
// export function isOdd(number) {
//   if(number === 0) return false;
//   else if(number === 1) return true;
//   else if(number === 2) return false;
//   else if(number === 3) return true;
//   else if(number === 4) return false;
//   else if(number === 5) return true;
//   else if(number === 6) return false;
//   else if(number === 7) return true;
//   else if(number === 8) return false;
//   else if(number === 9) return true;
//   else if(number === 10) return false;
// }
console.log(generateIsOddCode(15));
// returns:
// export function isOdd(number) {
//   if(number === 0) return false;
//   else if(number === 1) return true;
//   else if(number === 2) return false;
//   else if(number === 3) return true;
//   else if(number === 4) return false;
//   else if(number === 5) return true;
//   else if(number === 6) return false;
//   else if(number === 7) return true;
//   else if(number === 8) return false;
//   else if(number === 9) return true;
//   else if(number === 10) return false;
//   else if(number === 11) return true;
//   else if(number === 12) return false;
//   else if(number === 13) return true;
//   else if(number === 14) return false;
//   else if(number === 15) return true;
// }
Running Tests

In order to run tests, first install the packages then run the tests. Like so:

pnpm install && pnpm test
Building package

In order to build the package, run the following command:

pnpm build

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

License

Released under the MIT License.


is-odd-code-generator-typescript's People

Contributors

anmolshres avatar

Stargazers

Anmol Shrestha avatar

Watchers

 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.