Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snippets] Added several new mathematical snippets for JavaScript. #179

Merged
merged 7 commits into from
Jan 6, 2025

Conversation

JanluOfficial
Copy link
Contributor

Description

Added a bunch of snippets regarding math functions in JavaScript. These include the following:

  • Combinations, which calculate the number of combinations (denoted as C(n,r) or "n choose r"), which determines how many ways you can select r items from n items without considering the order.
  • Cross Product, which computes the cross product of two 3D vectors, which results in a vector perpendicular to both.
  • Dot Product, which computes the dot product of two vectors, which is the sum of the products of corresponding elements.
  • Error function, which computes the error function (erf(x)) for a given input x, which is a mathematical function used frequently in probability, statistics, and partial differential equations.
  • Least common multiple, which computes the least common multiple (LCM) of two numbers 𝑎 and b. The LCM is the smallest positive integer that is divisible by both a and b.
  • Matrix Multiplication, which multiplies two matrices, where the number of columns in the first matrix equals the number of rows in the second.
  • Modular Inverse, which computes the modular multiplicative inverse of a number a under modulo m, which is the integer x such that (a*x) mod m=1.
  • Prime Number, which checks that the number is a prime number.
    I also updated the tags for greatest common divisor, which I added as a snippet in [Snippet] Added code snippet for Greatest Common Divisor in JS #170 .

Type of Change

  • ✨ New snippets
  • 🛠 Improvement to an existing snippet
  • 🐞 Bug fix
  • 📖 Documentation update
  • 🔧 Other (please describe):

Checklist

  • I have tested my code and verified it works as expected.
  • My code follows the style and contribution guidelines of this project.
  • Comments are added where necessary for clarity.
  • Documentation has been updated (if applicable).
  • There are no new warnings or errors from my changes.

Related Issues

None

Additional Context

I let ChatGPT help me with explaining and occasionally writing the JavaScript required for these snippets, but I double checked that everything works using node.js, as well as on a about:blank page in the DevTools of Microsoft Edge.

Screenshots (Optional)

Click to view screenshots

image

Copy link
Collaborator

@Mathys-Gasnier Mathys-Gasnier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it looks good, but i'm not a math guy myself, so let's wait on another review and I think we will be good

@JanluOfficial
Copy link
Contributor Author

@Mathys-Gasnier You can ask ChatGPT if none of the other reviewers know this math. Wouldn't expect anyone to understand it anyways.

Copy link
Collaborator

@psychlone77 psychlone77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, almost all of these functions are available in the mathjs library, So, maybe include how to perform the same calculation using that library as well. I like these snippets, but anyone who wants to do a lot of complex calculations like erf might be better of using the library. @Mathys-Gasnier.

@Mathys-Gasnier
Copy link
Collaborator

IMO we shouldn't take into account external dependencies when deciding if snippets should be added, the reason being that some people don't like adding lots of deps to their project (which is a good thing seeing how NPM packages keep failing in the last couple of years)

@JanluOfficial
Copy link
Contributor Author

JanluOfficial commented Jan 5, 2025

IMO we shouldn't take into account external dependencies when deciding if snippets should be added, the reason being that some people don't like adding lots of deps to their project (which is a good thing seeing how NPM packages keep failing in the last couple of years)

I agree with Mathys, since I personally don't like bloating up my projects with random packages. Aside from that, I also intended for people to be able to just copy and paste them into a website that is made only with HTML, CSS and bare bones JS, no node.js and npm stuff. That said, if a separate "Node.js" language category is added, I may add snippets on how to use mathjs for those.

Copy link
Collaborator

@psychlone77 psychlone77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. I too now agree on the package bloating 🫡 .
Finally, thank you for your contribution to the project @JanluOfficial.

@JanluOfficial
Copy link
Contributor Author

You're welcome @psychlone77
I intend to keep contributing in the future, unless I get hospitalized or something.

@psychlone77 psychlone77 merged commit 34bd82f into technoph1le:main Jan 6, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants