Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

strong-roots-capital/percentage-change

Repository files navigation

percentage-change

Build status

Binary operator of percentage-change

Install

npm install percentage-change

Use

percentageChange(start: number, end: number): Option‹number›

Binary operator of percentage-change

Parameters:

Name Type
start number
end number

Returns: Option‹number›

import { percentageChange } from "percentage-change";
import { some, none } from "fp-ts/Option";

/* Standard use */
percentageChange(100, 200);
//=>some(100)

percentageChange(100, 75);
//=>some(-25)

/* Special cases */
percentageChange(0, 0);
//=>some(0)

percentageChange(0, 100);
//=>some(Infinity)

percentageChange(100, 0);
//=>some(-100)

percentageChange(NaN, 0);
//=>none

percentageChange(0, NaN);
//=>none

percentageChange(Infinity, 0); // -Infinity works the same way
//=>none

percentageChange(0, Infinity); // -Infinity works the same way
//=>none

Option type compliant with the fantasy-land specification.