@akmjenkins/nearest
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@akmjenkins/nearest

npm version Coverage Status Build Status Bundle Phobia

Rounds a number to the nearest N

import nearest from '@akmjenkins/nearest';

const roundToNearest10 = nearest(10);

roundToNearest10(5); // 10
roundToNearest10(4); // 0

const roundUpToNearest10 = nearest(10,Math.ceil);

roundUpToNearest10(5); // 10
roundUpToNearest10(1); // 10
roundUpToNearest10(11); // 20

const roundDownToNearest10 = nearest(10,Math.floor);

roundDownToNearest10(5); // 0
roundDownToNearest10(1); // 0
roundDownToNearest10(11); // 10
roundDownToNearest10(19); // 10

Or in the browser (creates a global nearest)

<script src="https://unpkg.com/@akmjenkins/nearest">
    const roundToNearest10 = nearest(10);
    roundToNearest10(5); // 10
</script>

Readme

Keywords

none

Package Sidebar

Install

npm i @akmjenkins/nearest

Weekly Downloads

0

Version

1.0.3

License

ISC

Unpacked Size

3.21 kB

Total Files

6

Last publish

Collaborators

  • akmjenkins