harshil-math
v1.4.1
Published
const math = require("harshil-math");
Readme
This is build upon Math function of common javascript
Using this, you can do this with numbers:
- add()
- addMore()
- multiply()
- multiplyMore()
- divide()
- divideMore()
- minus()
- minusMore()
- percent()
- fix()
- squareOf()
- getPct()
- generateRandom()
- positive()
- negative()
- compare()
- power()
- isPositive()
- isNegative()
- getMax()
- getMin()
- restrictBetween()
- isPrime()
- average()
- median()
- mode()
- toRoman()
- formatWithCommas()
you can do this with arrays
- shuffleArray()
- uniqueInArray()
you can also check leap year as well by using
- isLeapYear()
const math = require("harshil-math");
console.log("math.add", math.add(1, 3)); // 4
console.log("math.addMore", math.addMore(45, 4, 2, 3)); // 54
console.log("math.multiply", math.multiply(1, 3)); // 3
console.log("math.multiplyMore", math.multiplyMore(3, 4, 2, 5)); // 120
console.log("math.divide", math.divide(6, 3)); // 2
console.log("math.divideMore", math.divideMore(45, 5, 3)); // 3
console.log("math.minus", math.minus(1, 3)); // -2
console.log("math.minusMore", math.minusMore(45, 4, 2, 3)); // 36
console.log("math.percent", math.percent(52)); // "52%"
console.log("math.fix", math.fix(45.522, 1)); // 45.5
console.log("math.fix", math.fix(45.528, 2)); // 45.53
console.log("math.squareOf", math.squareOf(6)); // 36
console.log("math.getPct", math.getPct(10, 50)); // 20
console.log("math.generateRandom", math.generateRandom(10)); // generate random number less than 10
console.log("math.positive", math.positive(-10)); // 10
console.log("math.negative", math.negative(10)); // -10
console.log("math.compare", math.compare(10, 10)); // equal
console.log("math.compare", math.compare(10, 20)); // less
console.log("math.compare", math.compare(20, 10)); // greater
console.log("math.power", math.power(2, 4)); // 16
console.log("math.isPositive", math.isPositive(2)); // true
console.log("math.isPositive", math.isPositive(-2)); // false
console.log("math.isNegative", math.isNegative(2)); // false
console.log("math.isNegative", math.isNegative(-2)); // true
console.log("math.getMax", math.getMax(2, 4, 1, 32, 3, 133, 22, 31)); // 133
console.log("math.getMin", math.getMin(2, 4, 1, 31, 3, 133, 22, 31)); // 1
console.log("math.restrictBetween", math.restrictBetween(3, 2, 4)); // 3
console.log("math.restrictBetween", math.restrictBetween(5, 2, 4)); // 4
console.log("math.isPrime", math.isPrime(1)); // false
console.log("math.isPrime", math.isPrime(2)); // true
console.log("math.isPrime", math.isPrime(3)); // true
console.log("math.average", math.average(2, 4, 3, 2, 9)); // 4
console.log("math.median", math.median(2, 4, 3, 2, 9)); // 3
console.log("math.mode", math.mode(2, 4, 3, 2, 9)); // 2
console.log("math.toRoman", math.toRoman(1)); // I
console.log("math.formatWithCommas", math.formatWithCommas(100000)); // 1,00,000
console.log("math.shuffleArray", math.shuffleArray([1, 3, 2, 5, 7])); // shuffle elements in any order
console.log("math.uniqueInArray", math.uniqueInArray([1, 3, 4, 3, 2, 1])); // [4, 2]
console.log("math.isLeapYear", math.isLeapYear(2025)); // false
