Node.js Math Library

I made a package that contains several math functions to make your life easier.

This will published to NPM once I find a name for it.

The package is written entirely in TypeScript.

GitHub: GitHub - ValiantWind/Math-Utilities: A Set of Math Functions and such I made because I was bored
Repl: https://replit.com/@ValiantWind/Math-Utilities?v=1


Why did you take time out of your life to create something as tedious as this?

Two reasons.

  1. I get bored of my current projects sometimes.

  2. I showed my Calculus teacher my Calculators Project and he was impressed about the fact that Iā€™m trying to make a website for several types of Calculators.

    • He asked if I could make a set of functions and tools that could help with general math equations and formulas and such, and that if I managed to do this, heā€™d give me extra credit. Thatā€™s very cool of him.

Some of these functions are a waste of time to make, since you only need one line to replicate it. Why bother to make these?

A: Why not make it? I wanted to include everything. Whether itā€™s easy or hard :slight_smile:


Contributing

Contributing is always welcome, even encouraged. It would especially be helpful for complicated math formulas that will take my lots of time to implement :upside_down_face:

Future Example Use:

// Common JS
const { Algebra, Arithmetic, Calculus, Converters } = require("math-functions");

// ES6
import { Algebra, Arithmetic, Calculus, Converters } from "math-functions";

console.log(Algebra.getSlope(1, 2, 9, 6)); // 0.5
console.log(Arithmetic.getEvens[(1, 2, 3, 5, 6, 9, 0, 69, 420)]); // [2, 6, 0, 420]
console.log(Calculus.getFactorial(5)); // 120
console.log(Converters.CToK(30)); // 303
console.log(Geometry.getCircumference(30)); // 188.49...

Credits

The JavaScript Snippets from the the 30 Seconds of Code Repository. Saved me some time.

2 Likes

nice, is this a joke package like is-odd or XD?

Not a joke package. :slight_smile: There is a method called isOdd and another called isEven though haha

It contains the simplest of things to the most complicated things.

It doesnā€™t contain everything, but I plan on adding as much as I can when I have time.

1 Like

So I can add stuff right?

Yes.

You can fork the github repository, make the changes you want to add to the package and then create a pull request.

1 Like

Also note that when contributing, make sure you arenā€™t using any APIs or external packages. I want the library to be zero-dependencies at all times, with all functions written from scratch.

Iā€™ll try, Iā€™m new, but Iā€™m interested and like math

1 Like

Does it have a gcd algorithm yet?

I donā€™t believe so, Iā€™d check myself just in case

1 Like

I donā€™t know code, is this correct?

function getdistance(x1, y1, x2, y2) {
  const xdistance = x2 - x1;
  const ydistance = y2 - y1;
  const idk = xdistance**2 + ydistance**2;
  return Math.pow(idk, 1 / 2);
}

I donā€™t know what to do about the bold thing

1 Like

You can make a code block
There are two types of code blocks, and you make them using this character: `

The first is like this: `` ā† insert code between the two characters, and it looks like this. It is good for inline code statements.

The other option is a full code block which is made using six characters like this: `````` where the code goes in between with three on each side. This type of code block can go across multiple lines, like this:

def func():
    print("Hello World!")

Also gcd means greatest common divisor :slight_smile:

2 Likes

Edited to make a code block, dunno why youā€™d use Math.pow over Math.sqrt.

3 Likes

I can make right now. Give me a moment :slight_smile:

Edit: Added

1 Like

Hereā€™s a list(some of these are ehh):
-MAD
-Volume of sphere, cylinder, cone
-Area of a regular polygon
-Area of triangle, trapezoid, and rhombus
-Simplifying expressions
-Solving equations
-Prime factorization
-Scientific notation
-Pythagorean theorem
-Rounding

You should add stuff with primes. Feel free to steal borrow code from my prime-package-for-primes since I have no idea where to add a file for that stuff in your repo.

2 Likes

Thanks. Will do.

Alsoā€™s here how to contribute:

  1. Come up with method/function that isnā€™t apart of the package already
  2. Fork the repository and create a function in the appropriate math category (Arithmetic methods go in src/Math/Arithmetic.ts, Calculus methods go in src/Math/Calculus.ts, etc)
  3. Pull Request

Requirements:

  • The function parameters must have types and itā€™s own return type. The return type canā€™t directly be a primitive.

    Example:

export type isPrime = boolean;

// Must be this
function isPrime(num: number): isPrime {
   // Code here
}


// Not this
function isPrime(num): boolean {

}
  • No packages. The functions must be made manually (I want the package to have zero dependencies)
1 Like

So in this case, you would fork the repo.

Then you would modify the src/Math/Arithmetic.ts file by adding this function:

export type isPrime = boolean;

function isPrime(num: number): isPrime {

  if (number < 2) {

    return false;

  }

  for (i = 2; i < number; i++) {

    if (number % i === 0) {

      return false;

    }

  }

  return true;

}

and then create a pull request.

Let me know when youā€™ve made the pull request.