@santi100/factorial-lib
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Santi's Sorting Library

Build Status npm homepage GitHub stars License Bundlephobia stats

  • 🚀 Lightweight and fast^
  • 👴 ES3-compliant*
  • 💻 Portable between the browser and Node.js

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, or NaN if it's infinite, itself NaN 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.

Package Sidebar

Install

npm i @santi100/factorial-lib

Weekly Downloads

3

Version

0.0.2

License

MIT

Unpacked Size

34.2 kB

Total Files

39

Last publish

Collaborators

  • santi100a