num-utils

1.0.5 • Public • Published

Build Status Coverage Status GitHub license npm version npm bundle size (minified) node npm GitHub release GitHub contributors GitHub issues GitHub issues-closed GitHub pull-requests

num-utils

A small and simple library for number utility functions

Installation

npm install num-utils

Usage

    var nu = require('num-utils');
    nu.isEven(3); // => false
 
    nu.isNegative(-5); // => true

Divisibility Functions

    nu.isDivisibleBy3(5); // => false
    nu.isDivisibleBy3(27); // => true
 
    nu.isDivisibleBy(22, 4); // => false

Range Functions

    nu.isInRange(10, 2, 23); // => true
    nu.isInRangeMinInc(4, 4, 9); // => true
    nu.getRandomInRange(10, 20); // => 14

Mathematical Functions

    nu.sumOfNumbers(5); // => 15
    nu.sumOfNumbers([1,2,3,4]); // => 10
    nu.sumOfNumbers(5,10); // => 15, any number of arguments
    nu.calcAverage([1,2,3,4,5]); // => 3
 
    nu.sumOfNumbersBetween(2, 5); // => 9, does not include 2,5
    nu.sumOfNumbersFrom(2, 5); // => 14, including 2 and 5
    
    nu.sumOfSquares(2, 3, 4); // => 29
    nu.sumOfSquares([1, 2, 3, 4]); // => 30
    nu.sumOfCubes(2, 3, 4); // => 99

Sorting

    nu.sortAsc(23, 8, 12, 54); // => [ 8, 12,23, 54 ]
    nu.sortDesc([23, 8, 12, 54]); // => [ 54, 23, 12, 8 ]

Other Calculation Functions

    nu.getRandomNumberWithLength(3); // => 184
    nu.countDuplicates([1,1,2,2,2,3,3,4,5,5,5,6,6,6,7,7,8]); // => { '1': 2, '2': 3, '3': 2, '5': 3, '6': 3, '7': 2 }
    nu.isPythagoreanTriplets(6, 8 ,10); // => true
    nu.hasIntSquareRoot(20); // => false

Tests

npm test

Readme

Keywords

none

Package Sidebar

Install

npm i num-utils

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

20.5 kB

Total Files

11

Last publish

Collaborators

  • akbeeram