is-odd-code-generator
v1.0.2
Published
Library to generate JavaScript code that can determine if a given number is odd
Downloads
28
Maintainers
Readme
is-odd-code-generator
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;
// }
In order to run tests, first install the packages then run the tests. Like so:
pnpm install && pnpm test
In order to build the package, run the following command:
pnpm build
About
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
License
Released under the MIT License.