am-i-even-or-odd
v0.2.0
Published
Is your number even or odd tho?
Readme
Am I Even Or Odd
Is your number even or odd tho?
Yes, n % 2 === 0 does the same thing.
Installation
npm install am-i-even-or-oddUsage
CommonJS:
const { isItEvenTho, isItOddTho } = require('am-i-even-or-odd');
console.log(isItEvenTho(4)); // true
console.log(isItOddTho(5)); // trueESM / TypeScript:
import { isItEvenTho, isItOddTho } from 'am-i-even-or-odd';
console.log(isItEvenTho(4)); // true
console.log(isItOddTho(5)); // trueError handling
Only integers are accepted. Floats, strings, null, undefined,
booleans, NaN, and numbers outside JavaScript's safe integer range
all throw a TypeError with a message explaining why, rather than
silently returning a possibly-wrong answer:
isItEvenTho(4.5);
// TypeError: expected an integer, got number (4.5). Non-integer
// values aren't supported to avoid ambiguity around what counts
// as 'even' or 'odd'.Command line
Installing the package also gives you a CLI:
$ npx am-i-even-or-odd 42
even
$ npx am-i-even-or-odd 7 --fun
7 is is even! Kidding it's obviously ODD.--fun swaps the plain even/odd output for a random one-liner
with a bit more personality. Invalid input prints a usage error and
exits with a non-zero status code, so it plays nice in scripts.
Development
git clone https://github.com/KenKambi/am-i-even-or-odd-js.git
cd am-i-even-or-odd-js
npm install
npm testContributions and issues are welcome — see the issue tracker.
License
MIT — see LICENSE.
