Santi's Sorting Library
What's this?
This is a small, lightweight library for computing the factorial of any positive finite integer.
Installation
- Via NPM:
npm install @santi100/factorial-lib
- Via Yarn:
yarn add @santi100/factorial-lib
- Via PNPM:
pnpm install @santi100/factorial-lib
API
-
function factorial(n: number): number;
Returns -1 if $n$ is negative, orNaN
if it's infinite, itselfNaN
or a float.
It takes the number for which the factorial is to be calculated, and returns $n!$
Usage
import { factorial } from '@santi100/factorial-lib'; // ESM
const { factorial } = require('@santi100/factorial-lib'); // CJS
console.log(factorial(5)); // prints 120
console.log(factorial(7)); // prints 5,040
console.log(factorial(-60)); // prints -1
console.log(factorial(3.5)); // prints NaN
console.log(factorial(NaN)); // prints NaN
console.log(factorial(Infinity)); // prints NaN
console.log(factorial(-Infinity)); // prints NaN
Contribute
Wanna contribute? File an issue or pull request! Look at the contribution instructions and make sure you follow the contribution Code of Conduct.
Disclaimers
*Hasn't been tested in an actual ES3 environment. Feel free to open an issue or pull request if you find any non-ES3 thing. See "Contribute" for instructions on how to do so.
^The source code is just a few kilobytes in size.