1.0.5 • Published 6 years ago
num-utils v1.0.5
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