Math Pro is an extensive math library which will help you to do the basic calculation of math. Besides basic calculation you can also do the sort like sort, search. Some number properties of math have also included here. If you fear math then this library is for you.
- * Support numbers, big numbers, arrays
- * Is compatible with JavaScript's built-in functions
- * Open source
- * All popular search methods
- * All popular sort methods
You can install math-pro from
NPM. Go to the link
and search for math-pro or you can install the package by
writing on your command line npm i math-pro
Wait for few seconds and the package will be installed in your
project.
To get started with the package you need to import the package in your file. You can either import the package in ES5 format or ES6 format.
ES5 format
Import full module
const mt = require('math-pro'); console.log(mt.addition(5, 6)); // 11Import specific module
const mt = require('math-pro/lib/basic') console.log(mt.addition(5,6)); // 11ES6 format
import mt from 'math-pro' console.log(mt.addition(5, 6)); // 11N.B: You may encounter an error while importing the package in ES6 format. To fix the error in your package.json file add "type": "module"
Addition
Passing array to add numbersmt.addition([2,3,4]) // 9Passing arguments to add numbers
mt.addition(2,3,4) // 9
Subtraction
Passing array to subtraction numbersmt.subtraction([2,3,4]) // -5Passing arguments to subtraction numbers
mt.subtraction(2,3,4) // -5
Multiplication
Passing array to multiply numbersmt.multiplication([2,3,4]) // 24Passing arguments to multiply numbers
mt.multiplication(2,3,4) // 24
Division
Passing array to division numbersmt.division([2,3,4]) // 0.16667Passing arguments to division numbers
mt.division(2,3,4) // 0.16667
Average
Passing array to average numbersmt.average([2,3,4]) // 3Passing arguments to average numbers
mt.average(2,3,4) // 3
Remainder
Passing arguments to remainder numbersmt.getRemainder(5,2) // 1
Minimum
Passing array to minimum numbersmt.getMinimum([2,3,4]) // 2Passing arguments to minimum numbers
mt.getMinimum(2,3,4) // 2
Maximum
Passing array to maximum numbersmt.getMaximum([2,3,4]) // 4Passing arguments to maximum numbers
mt.getMaximum(2,3,4) // 4
Digit To Array
Passing arguments and convert digit to arraymt.digitToArray(234) // [1,2,3]
Number To Chars
Passing arguments and convert number to charsmt.numberToChars(51) // AZ
Degs To Rads
Passing arguments and convert degs to radsmt.degsToRads(5) // 0.08726646259971647
Rads To Degs
Passing arguments and convert rads to degsmt.radsToDegs(0.08726646259971647) // 5
String To Number
Passing arguments and convert string to numbermt.stringToNumber("25") // 25
Convert Number
Passing arguments and convert convert numbermt.convertNumber('100111', 2, 16) // 27
isDivisor
Passing arguments and check isDivisormt.isDivisor(25,5) // true
isEven
Passing arguments and check isEvenmt.isEven(24) // true
isOdd
Passing arguments and check isOddmt.isOdd(24) // false
isPrime
Passing arguments and check isPrimemt.isPrime(7) // true
isPalindrome
Passing arguments and check isPalindromemt.isPalindrome(78987) // true
isPositive
Passing arguments and check isPositivemt.isPositive(50) // true
isNegative
Passing arguments and check isNegativemt.isNegative(50) // false
isPowerOfTwo
Passing arguments and check isPowerOfTwomt.isPowerOfTwo(32) // true
- Find the greatest common divisor (gcd)
- Round the number to specific number after point
- Fixed number after point
- Get factorial of a number
- Power of a number
- Get the fibonacci sequence of a number
- Get fibonacci sum of a given number
- Pascal triangle of a number
- All prime numbers up to the given number
- Get a random number between two number range
- Reverse a number
GCD
Passing array and calculate gcdmt.gcd([16,4,8]) // 4Passing arguments and calculate gcd
mt.gcd(16,4,8) // 4
Round
Passing arguments and round numbersmt.round(1.23456, 3) // 1.235
Fixed
Passing arguments and toFixed numbersmt.toFixed(1.23456, 3) // 1.234
Get Factorial
Passing arguments and get factorialmt.getFactorial(5) // 120
Big Power
Passing arguments and get big powermt.bigPower(3,3) // 27
Fib Sequence
Passing arguments and get fib sequencemt.fibSequence(3) // [ 1, 1, 2 ]
Fib Nth
Passing arguments and get fib Nthmt.fibNth(10) // 55
Pascal Triangle
Passing arguments and get pascal trianglemt.pascalTriangle(3) // [ 1, 3, 3, 1 ]
Get PrimeList
Passing arguments and get prime listmt.getPrimeList(5) // [ 2, 3, 5 ]
Random Number
Passing arguments and get random numbermt.randomNumber(3, 10) // 8
Reverse Number
Passing arguments and get reverse numbermt.reverseNumber(234) // 432
Binary search
Passing array and find target numbermt.binarySearch([2,3,4], 4) // 2
Linear search
Passing array and find target numbermt.linearSearch([3,4,2], 4) // 1
Jump Search
Passing array and find target numbermt.jumpSearch([3,4,2], 4) // 1
Ternary Search
Passing array and find target numbermt.ternarySearch([3,4,2], 4) // 1
Bubble Sort
Passing array and get sorted arraymt.bubbleSort([3,2,4]) // [2,3,4]
Merge Sort
Passing array and get sorted arraymt.mergeSort([3,2,4], "des") // [4,3,2]
mt.mergeSort([3,2,4], "asc") // [2,3,4]
Quick Sort
Passing array and get sorted arraymt.quickSort([3,2,4]) // [2,3,4]
Selection Sort
Passing array and get sorted arraymt.selectionSort([3,2,4]) // [2,3,4]
Insertion Sort
Passing array and get sorted arraymt.insertionSort([3,2,4]) // [2,3,4]