Introduction

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.

Features
  • * Support numbers, big numbers, arrays
  • * Is compatible with JavaScript's built-in functions
  • * Open source
  • * All popular search methods
  • * All popular sort methods
Install

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.

Usage

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)); 
// 11
Import specific module
const mt = require('math-pro/lib/basic')

console.log(mt.addition(5,6));
// 11
          
ES6 format
import mt from 'math-pro'

console.log(mt.addition(5, 6));
// 11
          
N.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"
Basic Methods

Addition

Passing array to add numbers
mt.addition([2,3,4])

// 9
              
Passing arguments to add numbers
mt.addition(2,3,4)

// 9
              

Subtraction

Passing array to subtraction numbers
  mt.subtraction([2,3,4])
  
  // -5
                
Passing arguments to subtraction numbers
  mt.subtraction(2,3,4)
  
  // -5
                

Multiplication

Passing array to multiply numbers
  mt.multiplication([2,3,4])
  
  // 24
                
Passing arguments to multiply numbers
  mt.multiplication(2,3,4)
  
  // 24
                

Division

Passing array to division numbers
  mt.division([2,3,4])
  
  // 0.16667
                
Passing arguments to division numbers
  mt.division(2,3,4)
  
  // 0.16667
                

Average

Passing array to average numbers
  mt.average([2,3,4])
  
  // 3
                
Passing arguments to average numbers
  mt.average(2,3,4)
  
  // 3
                

Remainder

Passing arguments to remainder numbers
  mt.getRemainder(5,2)
  
  // 1
                

Minimum

Passing array to minimum numbers
  mt.getMinimum([2,3,4])
  
  // 2
                
Passing arguments to minimum numbers
  mt.getMinimum(2,3,4)
  
  // 2
                

Maximum

Passing array to maximum numbers
  mt.getMaximum([2,3,4])
  
  // 4
                
Passing arguments to maximum numbers
  mt.getMaximum(2,3,4)
  
  // 4
                
Conversion Methods

Digit To Array

Passing arguments and convert digit to array
mt.digitToArray(234)

// [1,2,3]
              

Number To Chars

Passing arguments and convert number to chars
mt.numberToChars(51) 

// AZ
              

Degs To Rads

Passing arguments and convert degs to rads
mt.degsToRads(5)

// 0.08726646259971647
              

Rads To Degs

Passing arguments and convert rads to degs
mt.radsToDegs(0.08726646259971647)

// 5
              

String To Number

Passing arguments and convert string to number
mt.stringToNumber("25") 

// 25
              

Convert Number

Passing arguments and convert convert number
mt.convertNumber('100111', 2, 16)

// 27
              
Check Methods

isDivisor

Passing arguments and check isDivisor
mt.isDivisor(25,5)

// true
        

isEven

Passing arguments and check isEven
mt.isEven(24)

// true
        

isOdd

Passing arguments and check isOdd
mt.isOdd(24)

// false
        

isPrime

Passing arguments and check isPrime
mt.isPrime(7)

// true
        

isPalindrome

Passing arguments and check isPalindrome
mt.isPalindrome(78987)

// true
        

isPositive

Passing arguments and check isPositive
mt.isPositive(50)

// true
        

isNegative

Passing arguments and check isNegative
mt.isNegative(50)

// false
        

isPowerOfTwo

Passing arguments and check isPowerOfTwo
mt.isPowerOfTwo(32)

// true
        
Number Methods

GCD

Passing array and calculate gcd
  mt.gcd([16,4,8])
  
  // 4
          
Passing arguments and calculate gcd
  mt.gcd(16,4,8)
  
  // 4
          

Round

Passing arguments and round numbers
  mt.round(1.23456, 3)
  
  // 1.235
            

Fixed

Passing arguments and toFixed numbers
  mt.toFixed(1.23456, 3)
  
  // 1.234
            

Get Factorial

Passing arguments and get factorial
  mt.getFactorial(5)
  
  // 120
            

Big Power

Passing arguments and get big power
  mt.bigPower(3,3)
  
  // 27
            

Fib Sequence

Passing arguments and get fib sequence
  mt.fibSequence(3)
  
  // [ 1, 1, 2 ]
            

Fib Nth

Passing arguments and get fib Nth
  mt.fibNth(10)
  
  // 55
            

Pascal Triangle

Passing arguments and get pascal triangle
  mt.pascalTriangle(3)
  
  // [ 1, 3, 3, 1 ]	
            

Get PrimeList

Passing arguments and get prime list
  mt.getPrimeList(5)
  
  // [ 2, 3, 5 ]
            

Random Number

Passing arguments and get random number
  mt.randomNumber(3, 10)
  
  // 8
            

Reverse Number

Passing arguments and get reverse number
  mt.reverseNumber(234)
  
  // 432
            

Binary search

Passing array and find target number
    mt.binarySearch([2,3,4], 4) 
    
    // 2
            

Linear search

Passing array and find target number
    mt.linearSearch([3,4,2], 4)
    
    // 1
              

Jump Search

Passing array and find target number
    mt.jumpSearch([3,4,2], 4)
    
    // 1
              

Ternary Search

Passing array and find target number
    mt.ternarySearch([3,4,2], 4)
    
    // 1
              
Sort Methods

Bubble Sort

Passing array and get sorted array
    mt.bubbleSort([3,2,4]) 
    
    // [2,3,4]
            

Merge Sort

Passing array and get sorted array
    mt.mergeSort([3,2,4], "des") 
    
    // [4,3,2]
            
    mt.mergeSort([3,2,4], "asc") 
    
    // [2,3,4]
            

Quick Sort

Passing array and get sorted array
    mt.quickSort([3,2,4]) 
    
    // [2,3,4]
            

Selection Sort

Passing array and get sorted array
    mt.selectionSort([3,2,4]) 
    
    // [2,3,4]
            

Insertion Sort

Passing array and get sorted array
    mt.insertionSort([3,2,4]) 
    
    // [2,3,4]