npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

math-tools

v1.0.0

Published

MathTools - is a javascript/node.js module providing some advanced mathematics functionalities

Downloads

1,122

Readme

math-tools.js

======= MathTools - is a javascript/node.js module providing some advanced mathematics functionalities.

Installation

npm install math-tools

For the browser, you can install with bower:

bower install math-tools

Importing

nodejs

var mathTools = require('math-tools');

browser

<script src="math-tools.js"></script>

API Documentation

A standard import of var mathTools = require('math-tools') is assumed in all of the code examples. The import results in an object having the following public properties:

  • isNumber - a function that checks if the given value is a number.
  • isArray - a function that checks if the given value is an array.
  • isObject - a function that checks if the given value is an object.
  • isInteger - a function that checks if the given number is an integer.
  • isPrime - determine whether a number n is prime.
  • sum - determine the sum of a set of numbers.
  • subtraction - subtracts elements from one another in array.
  • product - determine the product of a set of numbers.
  • avg - calculate the average value of a set of numbers in array.
  • factorial - determine the factorial (n!) of a number n.
  • fibonacci - a function that generates the fibonacci numbers up to a number n.
  • gcd - determine the greastest common divisor amongst two integers.
  • lcm - determine the least common multiple amongst two integers.
  • standardDeviation - determine the standard deviation for a set of values.
  • adaptiveSimpsonQuadrature - calculate integral of a function from a to b using adaptive simpson quadrature.
  • trapezoidal - calculate integral of a function from a to b using trapezoidal rule.

Examples

  • isPrime: Determine whether a number n is prime.

    console.log(mathTools.isPrime(16)); // false
    console.log(mathTools.isPrime(17)); // true
  • sum: Determine the sum of a set of numbers.

    var s1 = mathTools.sum([1,2,3]);
    var s2 = mathTools.sum([{a: 1},{b: 2},{a: 3}], 'a');
    console.log(s1); // 6
    console.log(s2); // 4
  • subtraction: Subtracts elements from one another in array.

    var s1 = mathTools.subtraction([1,2,3]);
    var s2 = mathTools.subtraction([{a: 1},{b: 2},{a: 3}], 'a');
    console.log(s1); // -4
    console.log(s2); // -2
  • product: Determine the product of a set of numbers.

    var p1 = mathTools.product([1,2,3]);
    var p2 = mathTools.product([{a: 1},{b: 2},{a: 3}], 'a');
    console.log(p1); // 6
    console.log(p2); // 3
  • avg: Calculate the average value of a set of numbers in array.

    console.log(mathTools.avg([1,2,3,4,5])); // 3
  • factorial: Determine the factorial (n!) of a number n.

    console.log(mathTools.factorial(5)); // 120
  • fibonacci: Generates n fibonacci numbers.

    console.log(mathTools.fibonacci(5)); // [0, 1, 1, 2, 3]
    console.log(mathTools.fibonacci(12)); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
  • gcd: Calculate the greastest common divisor amongst two integers.

    console.log(mathTools.gcd(6,9)); // 3
  • lcm: Calculate the least common multiple amongst two integers.

    console.log(mathTools.gcd([6,9])); // 18
  • standardDeviation: Determine the standard deviation for a set of values.

    console.log(mathTools.standardDeviation([2,3,4,5])); // 1.118033988749895
  • adaptiveSimpson: Calculate integral of a function from a to b using adaptive simpson quadrature.

    	
      var myFunc = function(x) {
      	return 2 * x + 1;
      };
    	
    	console.log(adaptiveQuadrature(myFunc, 1, 2)); // 4
  • trapezoidal: Calculate integral of a function from a to b using Trapezoidal rule with n subintervals. By default, the value of subintervals is 200.

    	
      var myFunc = function(x) {
      	return 2 * x + 1;
      };
    	
      console.log(trapezoidRule(myFunc, 1, 2, 200)); // 4