From 5bf5b33b53c294c66727823d83b02bc4c4fd0972 Mon Sep 17 00:00:00 2001 From: matthew Date: Fri, 10 Feb 2023 17:25:44 -0500 Subject: [PATCH] Add README.md with basic information --- README.md | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 16c803c..7e894aa 100644 --- a/README.md +++ b/README.md @@ -1 +1,78 @@ -This is a list of useful math functions. +# JS-Math + +## Description +JS-Math is a library of math functions that allows you to perform common math operations on numbers and arrays. + +## Installation +1) First install nodejs https://nodejs.org/ +2) Verfiy nodejs and npm are installed with commands in the terminal, node -v and npm -v +3) Run the command npm install math + +## Usage +To use JS-Math import the module in your javascript file +```javascript +const jsMath = require('math'); +``` +To run the file, run the command node file_name.js + +## Functions +There are nine basic functions that can be utilized: samesign, copysign, add, sum, mul, prod, factorial, gcd, and lcm. + +#### Samesign +The samesign function takes two numbers as arguments and returns a boolean whether they have the sign same. +```javascript +jsMath.samesign(4, 5); //samesign(4, 5) => returns: true +``` +#### Copysign +The copy sign function takes two numbers as arguments and returns the first argument with the same sign as the second argument. +```javascript +jsMath.copysign(-3, 6); //copysign(-3, 6) => returns: 3 +``` +#### Add +The add function takes two numbers as arguments and returns their sum. +```javascript +jsMath.add(15, 11); //add(15, 11) => returns: 26 +``` +#### Sum +The sum function takes an array of numbers as an argument and returns their sum. +```javascript +jsMath.sum([2,3,4]); //sum([2,3,4]) => returns: 9 +``` +#### Mul +The mul function takes two numbers as arguments and returns their product. +```javascript +jsMath.mul(3,7); //mul(3,7) => returns: 21 +``` +#### Prod +The prod function takes an array of numbers as an argument and returns the product of the elements in the array. +```javascript +jsMath.prod([8,9,23]); //prod([8,9,23]) => returns: 1656 +``` +#### Factorial +The factorial function takes a number as an argument and returns the [factorial](https://en.wikipedia.org/wiki/Factorial). +```javascript +jsMath.factorial(7); //factorial(7) => returns: 5040 +``` +#### GCD +The gcd function takes two numbers as arguments and returns their [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). +```javascript +jsMath.gcd(126, 48); //gcd(126, 48) => returns: 6 +``` +#### LCM +The lcm function takes two numbers as arguments and returns their [least common mulitiple](https://en.wikipedia.org/wiki/Least_common_multiple). +```javascript +jsMath.lcm(24, 36) //lcm(24, 36) => returns: 72 +``` + +## Coffeescript +Additionally, there is a coffeescript file that can be compiled to a javascript file named math.js. + +To install coffeescript globally run the command npm install -g coffeescript + +To verify coffeescript is installed globally run the command coffee -v. + +To compile the coffeescript file run the command coffee -c math.coffee in the same directory as the math.coffee file. This will produce a math.js file. + +To read more about coffeescript visit https://coffeescript.org/ + +## License